mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Add SegmentedList.shrink
I was exploring std.zig.Tokenizer and wanted to compare performance of arrays, SegmentedList and ArrayList and needed SegmentedList.shrink to make the comparison "fair".
This commit is contained in:
parent
4c0163b69b
commit
81d9403dce
@ -201,6 +201,11 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
|
||||
self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);
|
||||
}
|
||||
|
||||
pub fn shrink(self: *Self, new_len: usize) void {
|
||||
assert(new_len <= self.len);
|
||||
self.len = new_len;
|
||||
}
|
||||
|
||||
pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {
|
||||
if (index < prealloc_item_count) {
|
||||
return &self.prealloc_segment[index];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user