authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-03 14:57:33-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-03 14:57:33-08:00
log702d014f07e1403e5b52a85b3cc290707e3dc8ef
tree5a0f9f0d726d91be96b778e9d7ef30c554a023ef
parent6188cb8e50882a55c90578114556c6d1b7073e9d

ArrayList: rename "AssumeCapacity" to "Reserved"

Follows the convention that a single word used to describe a function variant is desired if possible.

1 files changed, 115 insertions(+), 58 deletions(-)

lib/std/array_list.zig+115-58
......@@ -128,7 +128,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
128128 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
129129 // This addition can never overflow because `self.items` can never occupy the whole address space
130130 try self.ensureTotalCapacityPrecise(self.items.len + 1);
131 self.appendAssumeCapacity(sentinel);
131 self.appendReserved(sentinel);
132132 const result = try self.toOwnedSlice();
133133 return result[0 .. result.len - 1 :sentinel];
134134 }
......@@ -136,7 +136,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
136136 /// Creates a copy of this ArrayList, using the same allocator.
137137 pub fn clone(self: Self) Allocator.Error!Self {
138138 var cloned = try Self.initCapacity(self.allocator, self.capacity);
139 cloned.appendSliceAssumeCapacity(self.items);
139 cloned.appendSliceReserved(self.items);
140140 return cloned;
141141 }
142142
......@@ -150,13 +150,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
150150 dst[0] = item;
151151 }
152152
153 /// Deprecated. To be removed after 0.14.0 is tagged.
154 pub const insertAssumeCapacity = insertReserved;
155
153156 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.
154157 /// If `i` is equal to the length of the list this operation is
155 /// equivalent to appendAssumeCapacity.
158 /// equivalent to `appendReserved`.
156159 /// This operation is O(N).
157160 /// Asserts that there is enough capacity for the new item.
158161 /// Asserts that the index is in bounds or equal to the length.
159 pub fn insertAssumeCapacity(self: *Self, i: usize, item: T) void {
162 pub fn insertReserved(self: *Self, i: usize, item: T) void {
160163 assert(self.items.len < self.capacity);
161164 self.items.len += 1;
162165
......@@ -176,7 +179,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
176179 const new_len = try addOrOom(self.items.len, count);
177180
178181 if (self.capacity >= new_len)
179 return addManyAtAssumeCapacity(self, index, count);
182 return addManyAtReserved(self, index, count);
180183
181184 // Here we avoid copying allocated but unused bytes by
182185 // attempting a resize in place, and falling back to allocating
......@@ -187,7 +190,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
187190 const old_memory = self.allocatedSlice();
188191 if (self.allocator.resize(old_memory, new_capacity)) {
189192 self.capacity = new_capacity;
190 return addManyAtAssumeCapacity(self, index, count);
193 return addManyAtReserved(self, index, count);
191194 }
192195
193196 // Make a new allocation, avoiding `ensureTotalCapacity` in order
......@@ -204,6 +207,9 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
204207 return new_memory[index..][0..count];
205208 }
206209
210 /// Deprecated. To be removed after 0.14.0 is tagged.
211 pub const addManyAtAssumeCapacity = addManyAtReserved;
212
207213 /// Add `count` new elements at position `index`, which have
208214 /// `undefined` values. Returns a slice pointing to the newly allocated
209215 /// elements, which becomes invalid after various `ArrayList`
......@@ -212,7 +218,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
212218 /// Invalidates pre-existing pointers to elements at and after `index`, but
213219 /// does not invalidate any before that.
214220 /// Asserts that the index is in bounds or equal to the length.
215 pub fn addManyAtAssumeCapacity(self: *Self, index: usize, count: usize) []T {
221 pub fn addManyAtReserved(self: *Self, index: usize, count: usize) []T {
216222 const new_len = self.items.len + count;
217223 assert(self.capacity >= new_len);
218224 const to_move = self.items[index..];
......@@ -247,13 +253,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
247253 return unmanaged.replaceRange(self.allocator, start, len, new_items);
248254 }
249255
256 /// Deprecated. To be removed after 0.14.0 is tagged.
257 pub const replaceRangeAssumeCapacity = replaceRangeReserved;
258
250259 /// Grows or shrinks the list as necessary.
251260 /// Never invalidates element pointers.
252261 /// Asserts the capacity is enough for additional items.
253 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
262 pub fn replaceRangeReserved(self: *Self, start: usize, len: usize, new_items: []const T) void {
254263 var unmanaged = self.moveToUnmanaged();
255264 defer self.* = unmanaged.toManaged(self.allocator);
256 return unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
265 return unmanaged.replaceRangeReserved(start, len, new_items);
257266 }
258267
259268 /// Extends the list by 1 element. Allocates more memory as necessary.
......@@ -263,11 +272,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
263272 new_item_ptr.* = item;
264273 }
265274
275 /// Deprecated. To be removed after 0.14.0 is tagged.
276 pub const appendAssumeCapacity = appendReserved;
277
266278 /// Extends the list by 1 element.
267279 /// Never invalidates element pointers.
268280 /// Asserts that the list can hold one additional item.
269 pub fn appendAssumeCapacity(self: *Self, item: T) void {
270 const new_item_ptr = self.addOneAssumeCapacity();
281 pub fn appendReserved(self: *Self, item: T) void {
282 const new_item_ptr = self.addOneReserved();
271283 new_item_ptr.* = item;
272284 }
273285
......@@ -280,7 +292,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
280292 /// Asserts that the list is not empty.
281293 pub fn orderedRemove(self: *Self, i: usize) T {
282294 const old_item = self.items[i];
283 self.replaceRangeAssumeCapacity(i, 1, &.{});
295 self.replaceRangeReserved(i, 1, &.{});
284296 return old_item;
285297 }
286298
......@@ -303,13 +315,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
303315 /// Invalidates element pointers if additional memory is needed.
304316 pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void {
305317 try self.ensureUnusedCapacity(items.len);
306 self.appendSliceAssumeCapacity(items);
318 self.appendSliceReserved(items);
307319 }
308320
321 /// Deprecated. To be removed after 0.14.0 is tagged.
322 pub const appendSliceAssumeCapacity = appendSliceReserved;
323
309324 /// Append the slice of items to the list.
310325 /// Never invalidates element pointers.
311326 /// Asserts that the list can hold the additional items.
312 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
327 pub fn appendSliceReserved(self: *Self, items: []const T) void {
313328 const old_len = self.items.len;
314329 const new_len = old_len + items.len;
315330 assert(new_len <= self.capacity);
......@@ -323,16 +338,19 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
323338 /// Invalidates element pointers if additional memory is needed.
324339 pub fn appendUnalignedSlice(self: *Self, items: []align(1) const T) Allocator.Error!void {
325340 try self.ensureUnusedCapacity(items.len);
326 self.appendUnalignedSliceAssumeCapacity(items);
341 self.appendUnalignedSliceReserved(items);
327342 }
328343
344 /// Deprecated. To be removed after 0.14.0 is tagged.
345 pub const appendUnalignedSliceAssumeCapacity = appendUnalignedSliceReserved;
346
329347 /// Append the slice of items to the list.
330348 /// Never invalidates element pointers.
331349 /// This function is only needed when calling
332 /// `appendSliceAssumeCapacity` instead would be a compile error due to the
350 /// `appendSliceReserved` instead would be a compile error due to the
333351 /// alignment of the `items` parameter.
334352 /// Asserts that the list can hold the additional items.
335 pub fn appendUnalignedSliceAssumeCapacity(self: *Self, items: []align(1) const T) void {
353 pub fn appendUnalignedSliceReserved(self: *Self, items: []align(1) const T) void {
336354 const old_len = self.items.len;
337355 const new_len = old_len + items.len;
338356 assert(new_len <= self.capacity);
......@@ -373,7 +391,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
373391 if (m.len > available_capacity)
374392 return error.OutOfMemory;
375393
376 self.appendSliceAssumeCapacity(m);
394 self.appendSliceReserved(m);
377395 return m.len;
378396 }
379397
......@@ -388,12 +406,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
388406 @memset(self.items[old_len..self.items.len], value);
389407 }
390408
409 /// Deprecated. To be removed after 0.14.0 is tagged.
410 pub const appendNTimesAssumeCapacity = appendNTimesReserved;
411
391412 /// Append a value to the list `n` times.
392413 /// Never invalidates element pointers.
393414 /// The function is inline so that a comptime-known `value` parameter will
394415 /// have a more optimal memset codegen in case it has a repeated byte pattern.
395416 /// Asserts that the list can hold the additional items.
396 pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
417 pub inline fn appendNTimesReserved(self: *Self, value: T, n: usize) void {
397418 const new_len = self.items.len + n;
398419 assert(new_len <= self.capacity);
399420 @memset(self.items.ptr[self.items.len..new_len], value);
......@@ -499,14 +520,17 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
499520 // This can never overflow because `self.items` can never occupy the whole address space
500521 const newlen = self.items.len + 1;
501522 try self.ensureTotalCapacity(newlen);
502 return self.addOneAssumeCapacity();
523 return self.addOneReserved();
503524 }
504525
526 /// Deprecated. To be removed after 0.14.0 is tagged.
527 pub const addOneAssumeCapacity = addOneReserved;
528
505529 /// Increase length by 1, returning pointer to the new item.
506530 /// The returned pointer becomes invalid when the list is resized.
507531 /// Never invalidates element pointers.
508532 /// Asserts that the list can hold one additional item.
509 pub fn addOneAssumeCapacity(self: *Self) *T {
533 pub fn addOneReserved(self: *Self) *T {
510534 assert(self.items.len < self.capacity);
511535 self.items.len += 1;
512536 return &self.items[self.items.len - 1];
......@@ -522,12 +546,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
522546 return self.items[prev_len..][0..n];
523547 }
524548
549 /// Deprecated. To be removed after 0.14.0 is tagged.
550 pub const addManyAsArrayAssumeCapacity = addManyAsArrayReserved;
551
525552 /// Resize the array, adding `n` new elements, which have `undefined` values.
526553 /// The return value is an array pointing to the newly allocated elements.
527554 /// Never invalidates element pointers.
528555 /// The returned pointer becomes invalid when the list is resized.
529556 /// Asserts that the list can hold the additional items.
530 pub fn addManyAsArrayAssumeCapacity(self: *Self, comptime n: usize) *[n]T {
557 pub fn addManyAsArrayReserved(self: *Self, comptime n: usize) *[n]T {
531558 assert(self.items.len + n <= self.capacity);
532559 const prev_len = self.items.len;
533560 self.items.len += n;
......@@ -544,12 +571,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
544571 return self.items[prev_len..][0..n];
545572 }
546573
574 /// Deprecated. To be removed after 0.14.0 is tagged.
575 pub const addManyAsSliceAssumeCapacity = addManyAsSliceReserved;
576
547577 /// Resize the array, adding `n` new elements, which have `undefined` values.
548578 /// The return value is a slice pointing to the newly allocated elements.
549579 /// Never invalidates element pointers.
550580 /// The returned pointer becomes invalid when the list is resized.
551581 /// Asserts that the list can hold the additional items.
552 pub fn addManyAsSliceAssumeCapacity(self: *Self, n: usize) []T {
582 pub fn addManyAsSliceReserved(self: *Self, n: usize) []T {
553583 assert(self.items.len + n <= self.capacity);
554584 const prev_len = self.items.len;
555585 self.items.len += n;
......@@ -725,7 +755,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
725755 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
726756 // This addition can never overflow because `self.items` can never occupy the whole address space
727757 try self.ensureTotalCapacityPrecise(allocator, self.items.len + 1);
728 self.appendAssumeCapacity(sentinel);
758 self.appendReserved(sentinel);
729759 const result = try self.toOwnedSlice(allocator);
730760 return result[0 .. result.len - 1 :sentinel];
731761 }
......@@ -733,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
733763 /// Creates a copy of this ArrayList.
734764 pub fn clone(self: Self, allocator: Allocator) Allocator.Error!Self {
735765 var cloned = try Self.initCapacity(allocator, self.capacity);
736 cloned.appendSliceAssumeCapacity(self.items);
766 cloned.appendSliceReserved(self.items);
737767 return cloned;
738768 }
739769
......@@ -747,12 +777,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
747777 dst[0] = item;
748778 }
749779
780 /// Deprecated. To be removed after 0.14.0 is tagged.
781 pub const insertAssumeCapacity = insertReserved;
782
750783 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.
751784 /// If in` is equal to the length of the list this operation is equivalent to append.
752785 /// This operation is O(N).
753786 /// Asserts that the list has capacity for one additional item.
754787 /// Asserts that the index is in bounds or equal to the length.
755 pub fn insertAssumeCapacity(self: *Self, i: usize, item: T) void {
788 pub fn insertReserved(self: *Self, i: usize, item: T) void {
756789 assert(self.items.len < self.capacity);
757790 self.items.len += 1;
758791
......@@ -779,6 +812,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
779812 return managed.addManyAt(index, count);
780813 }
781814
815 /// Deprecated. To be removed after 0.14.0 is tagged.
816 pub const addManyAtAssumeCapacity = addManyAtReserved;
817
782818 /// Add `count` new elements at position `index`, which have
783819 /// `undefined` values. Returns a slice pointing to the newly allocated
784820 /// elements, which becomes invalid after various `ArrayList`
......@@ -787,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
787823 /// does not invalidate any before that.
788824 /// Asserts that the list has capacity for the additional items.
789825 /// Asserts that the index is in bounds or equal to the length.
790 pub fn addManyAtAssumeCapacity(self: *Self, index: usize, count: usize) []T {
826 pub fn addManyAtReserved(self: *Self, index: usize, count: usize) []T {
791827 const new_len = self.items.len + count;
792828 assert(self.capacity >= new_len);
793829 const to_move = self.items[index..];
......@@ -836,14 +872,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
836872 @memcpy(range[0..first.len], first);
837873 try self.insertSlice(allocator, after_range, rest);
838874 } else {
839 self.replaceRangeAssumeCapacity(start, len, new_items);
875 self.replaceRangeReserved(start, len, new_items);
840876 }
841877 }
842878
879 /// Deprecated. To be removed after 0.14.0 is tagged.
880 pub const replaceRangeAssumeCapacity = replaceRangeReserved;
881
843882 /// Grows or shrinks the list as necessary.
844883 /// Never invalidates element pointers.
845884 /// Asserts the capacity is enough for additional items.
846 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
885 pub fn replaceRangeReserved(self: *Self, start: usize, len: usize, new_items: []const T) void {
847886 const after_range = start + len;
848887 const range = self.items[start..after_range];
849888
......@@ -853,7 +892,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
853892 const first = new_items[0..range.len];
854893 const rest = new_items[range.len..];
855894 @memcpy(range[0..first.len], first);
856 const dst = self.addManyAtAssumeCapacity(after_range, rest.len);
895 const dst = self.addManyAtReserved(after_range, rest.len);
857896 @memcpy(dst, rest);
858897 } else {
859898 const extra = range.len - new_items.len;
......@@ -875,11 +914,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
875914 new_item_ptr.* = item;
876915 }
877916
917 /// Deprecated. To be removed after 0.14.0 is tagged.
918 pub const appendAssumeCapacity = appendReserved;
919
878920 /// Extend the list by 1 element.
879921 /// Never invalidates element pointers.
880922 /// Asserts that the list can hold one additional item.
881 pub fn appendAssumeCapacity(self: *Self, item: T) void {
882 const new_item_ptr = self.addOneAssumeCapacity();
923 pub fn appendReserved(self: *Self, item: T) void {
924 const new_item_ptr = self.addOneReserved();
883925 new_item_ptr.* = item;
884926 }
885927
......@@ -890,7 +932,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
890932 /// Asserts that the index is in bounds.
891933 pub fn orderedRemove(self: *Self, i: usize) T {
892934 const old_item = self.items[i];
893 self.replaceRangeAssumeCapacity(i, 1, &.{});
935 self.replaceRangeReserved(i, 1, &.{});
894936 return old_item;
895937 }
896938
......@@ -913,12 +955,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
913955 /// Invalidates element pointers if additional memory is needed.
914956 pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void {
915957 try self.ensureUnusedCapacity(allocator, items.len);
916 self.appendSliceAssumeCapacity(items);
958 self.appendSliceReserved(items);
917959 }
918960
961 /// Deprecated. To be removed after 0.14.0 is tagged.
962 pub const appendSliceAssumeCapacity = appendSliceReserved;
963
919964 /// Append the slice of items to the list.
920965 /// Asserts that the list can hold the additional items.
921 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
966 pub fn appendSliceReserved(self: *Self, items: []const T) void {
922967 const old_len = self.items.len;
923968 const new_len = old_len + items.len;
924969 assert(new_len <= self.capacity);
......@@ -932,14 +977,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
932977 /// Invalidates element pointers if additional memory is needed.
933978 pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void {
934979 try self.ensureUnusedCapacity(allocator, items.len);
935 self.appendUnalignedSliceAssumeCapacity(items);
980 self.appendUnalignedSliceReserved(items);
936981 }
937982
983 /// Deprecated. To be removed after 0.14.0 is tagged.
984 pub const appendUnalignedSliceAssumeCapacity = appendUnalignedSliceReserved;
985
938986 /// Append an unaligned slice of items to the list.
939 /// Only call this function if a call to `appendSliceAssumeCapacity`
987 /// Only call this function if a call to `appendSliceReserved`
940988 /// instead would be a compile error.
941989 /// Asserts that the list can hold the additional items.
942 pub fn appendUnalignedSliceAssumeCapacity(self: *Self, items: []align(1) const T) void {
990 pub fn appendUnalignedSliceReserved(self: *Self, items: []align(1) const T) void {
943991 const old_len = self.items.len;
944992 const new_len = old_len + items.len;
945993 assert(new_len <= self.capacity);
......@@ -986,7 +1034,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
9861034 if (m.len > available_capacity)
9871035 return error.OutOfMemory;
9881036
989 self.appendSliceAssumeCapacity(m);
1037 self.appendSliceReserved(m);
9901038 return m.len;
9911039 }
9921040
......@@ -1006,7 +1054,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
10061054 /// The function is inline so that a comptime-known `value` parameter will
10071055 /// have better memset codegen in case it has a repeated byte pattern.
10081056 /// Asserts that the list can hold the additional items.
1009 pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
1057 pub inline fn appendNTimesReserved(self: *Self, value: T, n: usize) void {
10101058 const new_len = self.items.len + n;
10111059 assert(new_len <= self.capacity);
10121060 @memset(self.items.ptr[self.items.len..new_len], value);
......@@ -1135,14 +1183,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
11351183 // This can never overflow because `self.items` can never occupy the whole address space
11361184 const newlen = self.items.len + 1;
11371185 try self.ensureTotalCapacity(allocator, newlen);
1138 return self.addOneAssumeCapacity();
1186 return self.addOneReserved();
11391187 }
11401188
1189 /// Deprecated. To be removed after 0.14.0 is tagged.
1190 pub const addOneAssumeCapacity = addOneReserved;
1191
11411192 /// Increase length by 1, returning pointer to the new item.
11421193 /// Never invalidates element pointers.
11431194 /// The returned element pointer becomes invalid when the list is resized.
11441195 /// Asserts that the list can hold one additional item.
1145 pub fn addOneAssumeCapacity(self: *Self) *T {
1196 pub fn addOneReserved(self: *Self) *T {
11461197 assert(self.items.len < self.capacity);
11471198
11481199 self.items.len += 1;
......@@ -1158,12 +1209,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
11581209 return self.items[prev_len..][0..n];
11591210 }
11601211
1212 /// Deprecated. To be removed after 0.14.0 is tagged.
1213 pub const addManyAsArrayAssumeCapacity = addManyAsArrayReserved;
1214
11611215 /// Resize the array, adding `n` new elements, which have `undefined` values.
11621216 /// The return value is an array pointing to the newly allocated elements.
11631217 /// Never invalidates element pointers.
11641218 /// The returned pointer becomes invalid when the list is resized.
11651219 /// Asserts that the list can hold the additional items.
1166 pub fn addManyAsArrayAssumeCapacity(self: *Self, comptime n: usize) *[n]T {
1220 pub fn addManyAsArrayReserved(self: *Self, comptime n: usize) *[n]T {
11671221 assert(self.items.len + n <= self.capacity);
11681222 const prev_len = self.items.len;
11691223 self.items.len += n;
......@@ -1180,12 +1234,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
11801234 return self.items[prev_len..][0..n];
11811235 }
11821236
1237 /// Deprecated. To be removed after 0.14.0 is tagged.
1238 pub const addManyAsSliceAssumeCapacity = addManyAsSliceReserved;
1239
11831240 /// Resize the array, adding `n` new elements, which have `undefined` values.
11841241 /// The return value is a slice pointing to the newly allocated elements.
11851242 /// Never invalidates element pointers.
11861243 /// The returned pointer becomes invalid when the list is resized.
11871244 /// Asserts that the list can hold the additional items.
1188 pub fn addManyAsSliceAssumeCapacity(self: *Self, n: usize) []T {
1245 pub fn addManyAsSliceReserved(self: *Self, n: usize) []T {
11891246 assert(self.items.len + n <= self.capacity);
11901247 const prev_len = self.items.len;
11911248 self.items.len += n;
......@@ -1731,7 +1788,7 @@ test "ArrayList.replaceRange" {
17311788 }
17321789}
17331790
1734test "ArrayList.replaceRangeAssumeCapacity" {
1791test "ArrayList.replaceRangeReserved" {
17351792 const a = testing.allocator;
17361793
17371794 {
......@@ -1739,7 +1796,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
17391796 defer list.deinit();
17401797 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });
17411798
1742 list.replaceRangeAssumeCapacity(1, 0, &[_]i32{ 0, 0, 0 });
1799 list.replaceRangeReserved(1, 0, &[_]i32{ 0, 0, 0 });
17431800
17441801 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);
17451802 }
......@@ -1748,7 +1805,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
17481805 defer list.deinit();
17491806 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });
17501807
1751 list.replaceRangeAssumeCapacity(1, 1, &[_]i32{ 0, 0, 0 });
1808 list.replaceRangeReserved(1, 1, &[_]i32{ 0, 0, 0 });
17521809
17531810 try testing.expectEqualSlices(
17541811 i32,
......@@ -1761,7 +1818,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
17611818 defer list.deinit();
17621819 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });
17631820
1764 list.replaceRangeAssumeCapacity(1, 2, &[_]i32{ 0, 0, 0 });
1821 list.replaceRangeReserved(1, 2, &[_]i32{ 0, 0, 0 });
17651822
17661823 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);
17671824 }
......@@ -1770,7 +1827,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
17701827 defer list.deinit();
17711828 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });
17721829
1773 list.replaceRangeAssumeCapacity(1, 3, &[_]i32{ 0, 0, 0 });
1830 list.replaceRangeReserved(1, 3, &[_]i32{ 0, 0, 0 });
17741831
17751832 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);
17761833 }
......@@ -1779,7 +1836,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
17791836 defer list.deinit();
17801837 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });
17811838
1782 list.replaceRangeAssumeCapacity(1, 4, &[_]i32{ 0, 0, 0 });
1839 list.replaceRangeReserved(1, 4, &[_]i32{ 0, 0, 0 });
17831840
17841841 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);
17851842 }
......@@ -1839,7 +1896,7 @@ test "ArrayListUnmanaged.replaceRange" {
18391896 }
18401897}
18411898
1842test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1899test "ArrayListUnmanaged.replaceRangeReserved" {
18431900 const a = testing.allocator;
18441901
18451902 {
......@@ -1847,7 +1904,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
18471904 defer list.deinit(a);
18481905 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });
18491906
1850 list.replaceRangeAssumeCapacity(1, 0, &[_]i32{ 0, 0, 0 });
1907 list.replaceRangeReserved(1, 0, &[_]i32{ 0, 0, 0 });
18511908
18521909 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);
18531910 }
......@@ -1856,7 +1913,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
18561913 defer list.deinit(a);
18571914 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });
18581915
1859 list.replaceRangeAssumeCapacity(1, 1, &[_]i32{ 0, 0, 0 });
1916 list.replaceRangeReserved(1, 1, &[_]i32{ 0, 0, 0 });
18601917
18611918 try testing.expectEqualSlices(
18621919 i32,
......@@ -1869,7 +1926,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
18691926 defer list.deinit(a);
18701927 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });
18711928
1872 list.replaceRangeAssumeCapacity(1, 2, &[_]i32{ 0, 0, 0 });
1929 list.replaceRangeReserved(1, 2, &[_]i32{ 0, 0, 0 });
18731930
18741931 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);
18751932 }
......@@ -1878,7 +1935,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
18781935 defer list.deinit(a);
18791936 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });
18801937
1881 list.replaceRangeAssumeCapacity(1, 3, &[_]i32{ 0, 0, 0 });
1938 list.replaceRangeReserved(1, 3, &[_]i32{ 0, 0, 0 });
18821939
18831940 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);
18841941 }
......@@ -1887,7 +1944,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
18871944 defer list.deinit(a);
18881945 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });
18891946
1890 list.replaceRangeAssumeCapacity(1, 4, &[_]i32{ 0, 0, 0 });
1947 list.replaceRangeReserved(1, 4, &[_]i32{ 0, 0, 0 });
18911948
18921949 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);
18931950 }
......@@ -2021,7 +2078,7 @@ test "addManyAsArray" {
20212078
20222079 (try list.addManyAsArray(4)).* = "aoeu".*;
20232080 try list.ensureTotalCapacity(8);
2024 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
2081 list.addManyAsArrayReserved(4).* = "asdf".*;
20252082
20262083 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
20272084 }
......@@ -2031,7 +2088,7 @@ test "addManyAsArray" {
20312088
20322089 (try list.addManyAsArray(a, 4)).* = "aoeu".*;
20332090 try list.ensureTotalCapacity(a, 8);
2034 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
2091 list.addManyAsArrayReserved(4).* = "asdf".*;
20352092
20362093 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
20372094 }