pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) !void 190
191
192
193
194
195
196
197 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) !void {
if (self.capacity() >= new_capacity) return;
const old_memory = self.allocatedSlice();
const new_memory = try allocator.realloc(old_memory, new_capacity);
self.items.ptr = new_memory.ptr;
self.cap = new_memory.len;
}
If the current capacity is less than
new_capacity, this function will modify the array so that it can hold exactlynew_capacityitems. Invalidates element pointers if additional memory is needed.