-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
produce better OPcodes in strict IF or-conditions #12199
Comments
I'm not sure about the optimizer, but just wanted to point out that if we're going to do this, we may as well make it a lookup table instead of a linear search: https://3v4l.org/V5PeZ/vld function f1(string $name): bool {
if (in_array($name, ['__construct', '__destruct', '__unset', '__wakeup', '__clone'], true)) {
return true;
}
return false;
}
function f2(string $name): bool {
if ($name === '__construct'
|| $name === '__destruct'
|| $name === '__unset'
|| $name === '__wakeup'
|| $name === '__clone'
) {
return true;
}
return false;
}
function f3(string $name): bool {
return isset([
'__construct' => true,
'__destruct' => true,
'__unset' => true,
'__wakeup' => true,
'__clone' => true,
][$name]);
} Of these, |
|
When searching a constant array, already in PHP 7.2 the |
Sounds like we already have plenty alternatives. Thanks for the input. Closing. |
Description
could php-src be smarter about IF or-conditions which only contain strict-comparisions to make it produce the same opcodes as in a strict in-array call?
see https://3v4l.org/QQQMr/vld
indentified in phpstan/phpstan-src#2618 (comment)
The text was updated successfully, but these errors were encountered: