Skip to content

Don't evaluate GMP comparison multiple times #18321

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

Merged
merged 1 commit into from
Apr 14, 2025
Merged

Conversation

nielsdos
Copy link
Member

ZEND_THREEWAY_COMPARE evaluates its operands multiple times.

ZEND_THREEWAY_COMPARE evaluates its operands multiple times.
@@ -480,7 +480,8 @@ static int gmp_compare(zval *op1, zval *op2) /* {{{ */
return ZEND_UNCOMPARABLE;
}

return ZEND_THREEWAY_COMPARE(mpz_cmp(gmp_op1, gmp_op2), 0);
int ret = mpz_cmp(gmp_op1, gmp_op2); /* avoid multiple evaluations */
return ZEND_THREEWAY_COMPARE(ret, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

is it somehow possible to put this into the macro itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not without relying on non-portable GCC extensions.

@nielsdos nielsdos merged commit a142f10 into php:master Apr 14, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants