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 {...@@ -420,7 +420,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
420 self.capacity = 0;420 self.capacity = 0;
421 }421 }
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.
424 /// Invalidates pointers if additional memory is needed.425 /// Invalidates pointers if additional memory is needed.
425 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) Allocator.Error!void {426 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) Allocator.Error!void {
426 if (@sizeOf(T) == 0) {427 if (@sizeOf(T) == 0) {
...@@ -434,9 +435,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -434,9 +435,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
434 return self.ensureTotalCapacityPrecise(better_capacity);435 return self.ensureTotalCapacityPrecise(better_capacity);
435 }436 }
436437
437 /// Modify the array so that it can hold `new_capacity` items.438 /// If the current capacity is less than `new_capacity`, this function will
438 /// Like `ensureTotalCapacity`, but the resulting capacity is guaranteed439 /// modify the array so that it can hold exactly `new_capacity` items.
439 /// to be equal to `new_capacity`.
440 /// Invalidates pointers if additional memory is needed.440 /// Invalidates pointers if additional memory is needed.
441 pub fn ensureTotalCapacityPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {441 pub fn ensureTotalCapacityPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {
442 if (@sizeOf(T) == 0) {442 if (@sizeOf(T) == 0) {
...@@ -985,7 +985,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -985,7 +985,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
985 self.capacity = 0;985 self.capacity = 0;
986 }986 }
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.
989 /// Invalidates pointers if additional memory is needed.990 /// Invalidates pointers if additional memory is needed.
990 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {991 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
991 if (self.capacity >= new_capacity) return;992 if (self.capacity >= new_capacity) return;
...@@ -994,9 +995,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -994,9 +995,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
994 return self.ensureTotalCapacityPrecise(allocator, better_capacity);995 return self.ensureTotalCapacityPrecise(allocator, better_capacity);
995 }996 }
996997
997 /// Modify the array so that it can hold `new_capacity` items.998 /// If the current capacity is less than `new_capacity`, this function will
998 /// Like `ensureTotalCapacity`, but the resulting capacity is guaranteed999 /// modify the array so that it can hold exactly `new_capacity` items.
999 /// to be equal to `new_capacity`.
1000 /// Invalidates pointers if additional memory is needed.1000 /// Invalidates pointers if additional memory is needed.
1001 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {1001 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
1002 if (@sizeOf(T) == 0) {1002 if (@sizeOf(T) == 0) {