Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_filter: Remove unnecessary refcounting #17538

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6549,32 +6549,25 @@ PHP_FUNCTION(array_filter)
if (!string_key) {
ZVAL_LONG(key, num_key);
} else {
ZVAL_STR_COPY(key, string_key);
ZVAL_STR(key, string_key);
}
}
if (use_type != ARRAY_FILTER_USE_KEY) {
ZVAL_COPY(&args[0], operand);
ZVAL_COPY_VALUE(&args[0], operand);
}
fci.params = args;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat surprisingly, moving this line out of the loop into the ZEND_FCI_INITIALIZED(fci) decreases performance. I don't have an explanation for that.


if (zend_call_function(&fci, &fci_cache) == SUCCESS) {
bool retval_true;
zend_result result = zend_call_function(&fci, &fci_cache);
ZEND_ASSERT(result == SUCCESS);

zval_ptr_dtor(&args[0]);
if (use_type == ARRAY_FILTER_USE_BOTH) {
zval_ptr_dtor(&args[1]);
}
retval_true = zend_is_true(&retval);
zval_ptr_dtor(&retval);
if (!retval_true) {
continue;
}
} else {
zval_ptr_dtor(&args[0]);
if (use_type == ARRAY_FILTER_USE_BOTH) {
zval_ptr_dtor(&args[1]);
}
return;
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}

bool retval_true = zend_is_true(&retval);
zval_ptr_dtor(&retval);
if (!retval_true) {
continue;
}
} else if (!zend_is_true(operand)) {
continue;
Expand Down
Loading