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
RFC: array_find #14108
base: master
Are you sure you want to change the base?
RFC: array_find #14108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick look, have a few suggestions.
if (negate_condition) { | ||
retval_true = !retval_true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be simplified to:
if (negate_condition) { | |
retval_true = !retval_true; | |
} | |
retval_true ^= negate_condition; |
I believe this truth table matches both pieces of code to prove it:
retval_true | negate_condition | result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
However, it is late for me, so sorry if I made a mistake.
|
||
ZVAL_COPY(&args[0], operand); | ||
|
||
if (zend_call_function(&fci, &fci_cache) == SUCCESS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would save this to a variable which we can use to clean up below, and also mark it as EXPECTED
:
if (zend_call_function(&fci, &fci_cache) == SUCCESS) { | |
zend_result result = zend_call_function(&fci, &fci_cache); | |
if (EXPECTED(result == SUCCESS)) { |
} else { | ||
zval_ptr_dtor(&args[0]); | ||
zval_ptr_dtor(&args[1]); | ||
} | ||
} else { | ||
zval_ptr_dtor(&args[0]); | ||
zval_ptr_dtor(&args[1]); | ||
|
||
return FAILURE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses the suggestion of saving result
to a variable to coalesce the dtor code:
} else { | |
zval_ptr_dtor(&args[0]); | |
zval_ptr_dtor(&args[1]); | |
} | |
} else { | |
zval_ptr_dtor(&args[0]); | |
zval_ptr_dtor(&args[1]); | |
return FAILURE; | |
} | |
} | |
} | |
zval_ptr_dtor(&args[0]); | |
zval_ptr_dtor(&args[1]); | |
if (UNEXPECTED(result != SUCCESS)) { | |
return FAILURE; | |
} |
RFC: https://wiki.php.net/rfc/array_find