commit 1ffae59fec60816ff364b4ade93c6fc2fc1571cf (tree)
parent 839c453d880e22f2f120d62332b273380a215cc5
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 7 Feb 2025 00:47:43 -0800
std.heap.SmpAllocator: fix using wrong size class indices
Diffstat:
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/std/heap/SmpAllocator.zig b/lib/std/heap/SmpAllocator.zig
@@ -215,13 +215,11 @@ fn free(context: *anyopaque, memory: []u8, alignment: mem.Alignment, ra: usize)
fn sizeClassIndex(len: usize, alignment: mem.Alignment) usize {
return @max(
- @bitSizeOf(usize) - @clz(len - 1),
- @intFromEnum(alignment),
- min_class,
- );
+ @bitSizeOf(usize) - @clz(len + (@sizeOf(usize) - 1)),
+ @intFromEnum(alignment) + 1,
+ ) - min_class;
}
fn slotSize(class: usize) usize {
- const Log2USize = std.math.Log2Int(usize);
- return @as(usize, 1) << @as(Log2USize, @intCast(class));
+ return @as(usize, 1) << @intCast(class + min_class);
}