diff --git a/lib/std/sort/pdq.zig b/lib/std/sort/pdq.zig index 55bd17ae93e5..da2acb2d164a 100644 --- a/lib/std/sort/pdq.zig +++ b/lib/std/sort/pdq.zig @@ -41,10 +41,11 @@ const Hint = enum { /// which each take 2 `usize` parameters indicating the index of an item. /// Sorts in ascending order with respect to `lessThan`. pub fn pdqContext(a: usize, b: usize, context: anytype) void { + if (a == b) return; // slices of up to this length get sorted using insertion sort. const max_insertion = 24; // number of allowed imbalanced partitions before switching to heap sort. - const max_limit = std.math.floorPowerOfTwo(usize, b - a) + 1; + const max_limit = math.log2_int(usize, b - a) + 1; // set upper bound on stack memory usage. const Range = struct { a: usize, b: usize, limit: usize };