[php-src] PR #20517: Fix SORT_REGULAR with new transitive comparison functions
| From: | jmarble | Date: | Tue, 18 Nov 2025 03:43:59 +0000 |
| Subject: | [php-src] PR #20517: Fix SORT_REGULAR with new transitive comparison functions | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-34090@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/20517
Author: jmarble
### Summary
Fixes https://github.com/php/php-src/issues/20262
by making
SORT_REGULAR fall back to a fully transitive comparator whenever loose
comparisons would otherwise be non-transitive (e.g. numeric strings vs numeric zvals). That keeps
duplicates grouped so array_unique() and the sort family behave consistently.
### Highlights
- Introduce shared zend comparison helpers (long/double/string) and reuse them across both Zend and
ext/standard to avoid duplicating the transitive logic.
- Add transitivity detection plus a dedicated php_array_sort_regular() fast path so
only the arrays that need this comparator pay for it.
- Rework the sort entry points and array_unique() to call the fast path automatically
when required.
- Negligible performance regressions, with measurable gains of up to ~1.7x for sort()
and array_unique()