Skip to content

Commit 2fb5ea9

Browse files
committed
review
1 parent 8a67789 commit 2fb5ea9

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

ext/standard/array.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6509,6 +6509,22 @@ PHP_FUNCTION(array_reduce)
65096509
}
65106510
/* }}} */
65116511

6512+
/* Consumes `zv` */
6513+
static bool php_is_true(zval *zv)
6514+
{
6515+
switch (Z_TYPE_P(zv)) {
6516+
case IS_TRUE:
6517+
return true;
6518+
case IS_FALSE:
6519+
return false;
6520+
default: {
6521+
bool rv = zend_is_true(zv);
6522+
zval_ptr_dtor(zv);
6523+
return rv;
6524+
}
6525+
}
6526+
}
6527+
65126528
/* {{{ Filters elements from the array via the callback. */
65136529
PHP_FUNCTION(array_filter)
65146530
{
@@ -6571,9 +6587,7 @@ PHP_FUNCTION(array_filter)
65716587
RETURN_THROWS();
65726588
}
65736589

6574-
bool retval_true = zend_is_true(&retval);
6575-
zval_ptr_dtor(&retval);
6576-
if (!retval_true) {
6590+
if (!php_is_true(&retval)) {
65776591
continue;
65786592
}
65796593
} else if (!zend_is_true(operand)) {
@@ -6620,6 +6634,8 @@ static enum php_array_find_result php_array_find(const HashTable *array, zend_fc
66206634
if (!str_key) {
66216635
ZVAL_LONG(&args[1], num_key);
66226636
} else {
6637+
/* Allows copying the numeric branch, without this branch, into the iteration code
6638+
* that checks for the packed array flag. */
66236639
ZEND_ASSUME(!HT_IS_PACKED(array));
66246640
ZVAL_STR(&args[1], str_key);
66256641
}
@@ -6633,21 +6649,7 @@ static enum php_array_find_result php_array_find(const HashTable *array, zend_fc
66336649
return PHP_ARRAY_FIND_EXCEPTION;
66346650
}
66356651

6636-
bool retval_true;
6637-
switch (Z_TYPE(retval)) {
6638-
case IS_TRUE:
6639-
retval_true = !negate_condition;
6640-
break;
6641-
case IS_FALSE:
6642-
retval_true = negate_condition;
6643-
break;
6644-
default:
6645-
retval_true = zend_is_true(&retval) ^ negate_condition;
6646-
zval_ptr_dtor(&retval);
6647-
break;
6648-
}
6649-
6650-
if (retval_true) {
6652+
if (php_is_true(&retval) ^ negate_condition) {
66516653
if (result_value != NULL) {
66526654
ZVAL_COPY_DEREF(result_value, &args[0]);
66536655
}

0 commit comments

Comments
 (0)