pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void 365
366
367
368
369
370
371
372
373
374
375
376
377 pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void {
assert(new_len <= self.items.len);
// Cannot shrink to smaller than the current queue size without invalidating the heap property
assert(new_len >= self.len);
self.items = allocator.realloc(self.items[0..], new_len) catch |e| switch (e) {
error.OutOfMemory => { // no problem, capacity is still correct then.
self.items.len = new_len;
return;
},
};
}
Reduce allocated capacity to
new_len.