authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-01-11 16:09:32-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-13 19:58:22-08:00
log4dd3505e4329cf87a9ab5a7665ac2263fa2a4ec5
tree71b90ab69087e57ac441ae2896c3f48e083792c3
parent279607cae58f7be46335793df6a4a753d0a800aa

std.ArrayList: Clarify that ensureTotalCapacity/ensureTotalCapacityPrecise will never shrink the array

Closes #18499

1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/array_list.zig+8-8
......@@ -420,7 +420,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
420420 self.capacity = 0;
421421 }
422422
423 /// Modify the array so that it can hold at least `new_capacity` items.
423 /// If the current capacity is less than `new_capacity`, this function will
424 /// modify the array so that it can hold at least `new_capacity` items.
424425 /// Invalidates pointers if additional memory is needed.
425426 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) Allocator.Error!void {
426427 if (@sizeOf(T) == 0) {
......@@ -434,9 +435,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
434435 return self.ensureTotalCapacityPrecise(better_capacity);
435436 }
436437
437 /// Modify the array so that it can hold `new_capacity` items.
438 /// Like `ensureTotalCapacity`, but the resulting capacity is guaranteed
439 /// to be equal to `new_capacity`.
438 /// If the current capacity is less than `new_capacity`, this function will
439 /// modify the array so that it can hold exactly `new_capacity` items.
440440 /// Invalidates pointers if additional memory is needed.
441441 pub fn ensureTotalCapacityPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {
442442 if (@sizeOf(T) == 0) {
......@@ -985,7 +985,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
985985 self.capacity = 0;
986986 }
987987
988 /// Modify the array so that it can hold at least `new_capacity` items.
988 /// If the current capacity is less than `new_capacity`, this function will
989 /// modify the array so that it can hold at least `new_capacity` items.
989990 /// Invalidates pointers if additional memory is needed.
990991 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
991992 if (self.capacity >= new_capacity) return;
......@@ -994,9 +995,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
994995 return self.ensureTotalCapacityPrecise(allocator, better_capacity);
995996 }
996997
997 /// Modify the array so that it can hold `new_capacity` items.
998 /// Like `ensureTotalCapacity`, but the resulting capacity is guaranteed
999 /// to be equal to `new_capacity`.
998 /// If the current capacity is less than `new_capacity`, this function will
999 /// modify the array so that it can hold exactly `new_capacity` items.
10001000 /// Invalidates pointers if additional memory is needed.
10011001 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
10021002 if (@sizeOf(T) == 0) {