From: Dmitry Stogov Date: Mon, 21 Apr 2014 22:03:10 +0000 (+0400) Subject: Use fast comparison function X-Git-Tag: POST_PHPNG_MERGE~412^2~81^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b886d9ce1eb92dcc79c157f046142b1cb5eee271;p=php Use fast comparison function --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 50d064f91c..6dada188cf 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1216,31 +1216,43 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ ulong num_idx; zend_string *str_idx; zend_bool strict = 0; /* strict comparison or not */ - int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za|b", &value, &array, &strict) == FAILURE) { return; } if (strict) { - is_equal_func = is_identical_function; - } - - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { - is_equal_func(&res, value, entry TSRMLS_CC); - if (Z_LVAL(res)) { - if (behavior == 0) { - RETURN_TRUE; - } else { - if (str_idx) { - RETVAL_STR(STR_COPY(str_idx)); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + is_identical_function(&res, value, entry TSRMLS_CC); + if (Z_LVAL(res)) { + if (behavior == 0) { + RETURN_TRUE; } else { - RETVAL_LONG(num_idx); + if (str_idx) { + RETVAL_STR(STR_COPY(str_idx)); + } else { + RETVAL_LONG(num_idx); + } + return; } - return; } - } - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } else { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + if (fast_equal_function(&res, value, entry TSRMLS_CC)) { + if (behavior == 0) { + RETURN_TRUE; + } else { + if (str_idx) { + RETVAL_STR(STR_COPY(str_idx)); + } else { + RETVAL_LONG(num_idx); + } + return; + } + } + } ZEND_HASH_FOREACH_END(); + } RETURN_FALSE; }