Skip to content

Commit ea86a92

Browse files
committed
Optimize integer in_array with strict=true
It doesn't make sense that using in_array with strict=false is much faster for this case, due to lack of a specialized codepath.
1 parent 48ca5a1 commit ea86a92

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

ext/standard/array.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,21 +1554,39 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior)
15541554
ZEND_PARSE_PARAMETERS_END();
15551555

15561556
if (strict) {
1557-
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
1558-
ZVAL_DEREF(entry);
1559-
if (fast_is_identical_function(value, entry)) {
1560-
if (behavior == 0) {
1561-
RETURN_TRUE;
1562-
} else {
1563-
if (str_idx) {
1564-
RETVAL_STR_COPY(str_idx);
1557+
if (Z_TYPE_P(value) == IS_LONG) {
1558+
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
1559+
ZVAL_DEREF(entry);
1560+
if (Z_TYPE_P(entry) == IS_LONG && Z_LVAL_P(entry) == Z_LVAL_P(value)) {
1561+
if (behavior == 0) {
1562+
RETURN_TRUE;
15651563
} else {
1566-
RETVAL_LONG(num_idx);
1564+
if (str_idx) {
1565+
RETVAL_STR_COPY(str_idx);
1566+
} else {
1567+
RETVAL_LONG(num_idx);
1568+
}
1569+
return;
15671570
}
1568-
return;
15691571
}
1570-
}
1571-
} ZEND_HASH_FOREACH_END();
1572+
} ZEND_HASH_FOREACH_END();
1573+
} else {
1574+
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
1575+
ZVAL_DEREF(entry);
1576+
if (fast_is_identical_function(value, entry)) {
1577+
if (behavior == 0) {
1578+
RETURN_TRUE;
1579+
} else {
1580+
if (str_idx) {
1581+
RETVAL_STR_COPY(str_idx);
1582+
} else {
1583+
RETVAL_LONG(num_idx);
1584+
}
1585+
return;
1586+
}
1587+
}
1588+
} ZEND_HASH_FOREACH_END();
1589+
}
15721590
} else {
15731591
if (Z_TYPE_P(value) == IS_LONG) {
15741592
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {

0 commit comments

Comments
 (0)