diff options
| author | Jay Petacat <jay@jayschwa.net> | 2024-09-09 22:23:18 -0600 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-09-16 14:04:18 -0700 |
| commit | 812557bfde3c577b5f00cb556201c71ad5ed6fa4 (patch) | |
| tree | 78dc955c7aa665ea95f32a3820903f63c025aed7 /lib/compiler/aro | |
| parent | 7caa3d9da71c38665340247a1c2bf9bedb8db925 (diff) | |
| download | zig-812557bfde3c577b5f00cb556201c71ad5ed6fa4.tar.gz zig-812557bfde3c577b5f00cb556201c71ad5ed6fa4.zip | |
std: Restore conventional `compareFn` behavior for `binarySearch`
PR #20927 made some improvements to the `binarySearch` API, but one
change I found surprising was the relationship between the left-hand and
right-hand parameters of `compareFn` was inverted. This is different
from how comparison functions typically behave, both in other parts of
Zig (e.g. `std.math.order`) and in other languages (e.g. C's `bsearch`).
Unless a strong reason can be identified and documented for doing
otherwise, I think it'll be better to stick with convention.
While writing this patch and changing things back to the way they were,
the predicates of `lowerBound` and `upperBound` seemed to be the only
areas that benefited from the inversion. I don't think that benefit is
worth the cost, personally. Calling `Order.invert()` in the predicates
accomplishes the same goal.
Diffstat (limited to 'lib/compiler/aro')
| -rw-r--r-- | lib/compiler/aro/aro/Preprocessor.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/compiler/aro/aro/Preprocessor.zig b/lib/compiler/aro/aro/Preprocessor.zig index a8eb74a4a8..5a03cc0dff 100644 --- a/lib/compiler/aro/aro/Preprocessor.zig +++ b/lib/compiler/aro/aro/Preprocessor.zig @@ -271,7 +271,7 @@ fn clearBuffers(pp: *Preprocessor) void { pub fn expansionSlice(pp: *Preprocessor, tok: Tree.TokenIndex) []Source.Location { const S = struct { fn orderTokenIndex(context: Tree.TokenIndex, item: Tree.TokenIndex) std.math.Order { - return std.math.order(item, context); + return std.math.order(context, item); } }; |
