authorgravatar for wink@saville.comWink Saville <wink@saville.com> 2018-09-30 00:02:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-19 10:53:25-05:00
log81d9403dcea172ce2fdb44610c9350821109adae
treeb04c9a0ad55c82987ddd9d16af8dd4a8d8251e93
parent4c0163b69bafce753ee31e1bfa3ae0b5ba37fbf2

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".

1 files changed, 5 insertions(+), 0 deletions(-)

std/segmented_list.zig+5
...@@ -201,6 +201,11 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -201,6 +201,11 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
201 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);201 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);
202 }202 }
203203
204 pub fn shrink(self: *Self, new_len: usize) void {
205 assert(new_len <= self.len);
206 self.len = new_len;
207 }
208
204 pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {209 pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {
205 if (index < prealloc_item_count) {210 if (index < prealloc_item_count) {
206 return &self.prealloc_segment[index];211 return &self.prealloc_segment[index];