std.ArrayList: Fix compile error when @sizeOf(T) == 0

This commit is contained in:
Nils Koch 2025-12-17 17:54:31 +01:00 committed by Andrew Kelley
parent f1b2554023
commit 6473dc22fc

View file

@ -1362,11 +1362,11 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
return self.getLast();
}
const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
/// Called when memory growth is necessary. Returns a capacity larger than
/// minimum that grows super-linearly.
pub fn growCapacity(minimum: usize) usize {
if (@sizeOf(T) == 0) return math.maxInt(usize);
const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
return minimum +| (minimum / 2 + init_capacity);
}
};
@ -1751,6 +1751,14 @@ test "insert" {
try testing.expect(list.items[2] == 2);
try testing.expect(list.items[3] == 3);
}
{
var list: ArrayList(struct {}) = .empty;
defer list.deinit(a);
try list.insert(a, 0, .{});
try list.append(a, .{});
try testing.expect(list.items.len == 2);
}
}
test "insertSlice" {