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 {...@@ -128,7 +128,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
128 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {128 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
129 // This addition can never overflow because `self.items` can never occupy the whole address space129 // This addition can never overflow because `self.items` can never occupy the whole address space
130 try self.ensureTotalCapacityPrecise(self.items.len + 1);130 try self.ensureTotalCapacityPrecise(self.items.len + 1);
131 self.appendAssumeCapacity(sentinel);131 self.appendReserved(sentinel);
132 const result = try self.toOwnedSlice();132 const result = try self.toOwnedSlice();
133 return result[0 .. result.len - 1 :sentinel];133 return result[0 .. result.len - 1 :sentinel];
134 }134 }
...@@ -136,7 +136,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -136,7 +136,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
136 /// Creates a copy of this ArrayList, using the same allocator.136 /// Creates a copy of this ArrayList, using the same allocator.
137 pub fn clone(self: Self) Allocator.Error!Self {137 pub fn clone(self: Self) Allocator.Error!Self {
138 var cloned = try Self.initCapacity(self.allocator, self.capacity);138 var cloned = try Self.initCapacity(self.allocator, self.capacity);
139 cloned.appendSliceAssumeCapacity(self.items);139 cloned.appendSliceReserved(self.items);
140 return cloned;140 return cloned;
141 }141 }
142142
...@@ -150,13 +150,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -150,13 +150,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
150 dst[0] = item;150 dst[0] = item;
151 }151 }
152152
153 /// Deprecated. To be removed after 0.14.0 is tagged.
154 pub const insertAssumeCapacity = insertReserved;
155
153 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.156 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.
154 /// If `i` is equal to the length of the list this operation is157 /// If `i` is equal to the length of the list this operation is
155 /// equivalent to appendAssumeCapacity.158 /// equivalent to `appendReserved`.
156 /// This operation is O(N).159 /// This operation is O(N).
157 /// Asserts that there is enough capacity for the new item.160 /// Asserts that there is enough capacity for the new item.
158 /// Asserts that the index is in bounds or equal to the length.161 /// 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 {
160 assert(self.items.len < self.capacity);163 assert(self.items.len < self.capacity);
161 self.items.len += 1;164 self.items.len += 1;
162165
...@@ -176,7 +179,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -176,7 +179,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
176 const new_len = try addOrOom(self.items.len, count);179 const new_len = try addOrOom(self.items.len, count);
177180
178 if (self.capacity >= new_len)181 if (self.capacity >= new_len)
179 return addManyAtAssumeCapacity(self, index, count);182 return addManyAtReserved(self, index, count);
180183
181 // Here we avoid copying allocated but unused bytes by184 // Here we avoid copying allocated but unused bytes by
182 // attempting a resize in place, and falling back to allocating185 // attempting a resize in place, and falling back to allocating
...@@ -187,7 +190,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -187,7 +190,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
187 const old_memory = self.allocatedSlice();190 const old_memory = self.allocatedSlice();
188 if (self.allocator.resize(old_memory, new_capacity)) {191 if (self.allocator.resize(old_memory, new_capacity)) {
189 self.capacity = new_capacity;192 self.capacity = new_capacity;
190 return addManyAtAssumeCapacity(self, index, count);193 return addManyAtReserved(self, index, count);
191 }194 }
192195
193 // Make a new allocation, avoiding `ensureTotalCapacity` in order196 // Make a new allocation, avoiding `ensureTotalCapacity` in order
...@@ -204,6 +207,9 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -204,6 +207,9 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
204 return new_memory[index..][0..count];207 return new_memory[index..][0..count];
205 }208 }
206209
210 /// Deprecated. To be removed after 0.14.0 is tagged.
211 pub const addManyAtAssumeCapacity = addManyAtReserved;
212
207 /// Add `count` new elements at position `index`, which have213 /// Add `count` new elements at position `index`, which have
208 /// `undefined` values. Returns a slice pointing to the newly allocated214 /// `undefined` values. Returns a slice pointing to the newly allocated
209 /// elements, which becomes invalid after various `ArrayList`215 /// elements, which becomes invalid after various `ArrayList`
...@@ -212,7 +218,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -212,7 +218,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
212 /// Invalidates pre-existing pointers to elements at and after `index`, but218 /// Invalidates pre-existing pointers to elements at and after `index`, but
213 /// does not invalidate any before that.219 /// does not invalidate any before that.
214 /// Asserts that the index is in bounds or equal to the length.220 /// 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 {
216 const new_len = self.items.len + count;222 const new_len = self.items.len + count;
217 assert(self.capacity >= new_len);223 assert(self.capacity >= new_len);
218 const to_move = self.items[index..];224 const to_move = self.items[index..];
...@@ -247,13 +253,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -247,13 +253,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
247 return unmanaged.replaceRange(self.allocator, start, len, new_items);253 return unmanaged.replaceRange(self.allocator, start, len, new_items);
248 }254 }
249255
256 /// Deprecated. To be removed after 0.14.0 is tagged.
257 pub const replaceRangeAssumeCapacity = replaceRangeReserved;
258
250 /// Grows or shrinks the list as necessary.259 /// Grows or shrinks the list as necessary.
251 /// Never invalidates element pointers.260 /// Never invalidates element pointers.
252 /// Asserts the capacity is enough for additional items.261 /// 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 {
254 var unmanaged = self.moveToUnmanaged();263 var unmanaged = self.moveToUnmanaged();
255 defer self.* = unmanaged.toManaged(self.allocator);264 defer self.* = unmanaged.toManaged(self.allocator);
256 return unmanaged.replaceRangeAssumeCapacity(start, len, new_items);265 return unmanaged.replaceRangeReserved(start, len, new_items);
257 }266 }
258267
259 /// Extends the list by 1 element. Allocates more memory as necessary.268 /// 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 {...@@ -263,11 +272,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
263 new_item_ptr.* = item;272 new_item_ptr.* = item;
264 }273 }
265274
275 /// Deprecated. To be removed after 0.14.0 is tagged.
276 pub const appendAssumeCapacity = appendReserved;
277
266 /// Extends the list by 1 element.278 /// Extends the list by 1 element.
267 /// Never invalidates element pointers.279 /// Never invalidates element pointers.
268 /// Asserts that the list can hold one additional item.280 /// Asserts that the list can hold one additional item.
269 pub fn appendAssumeCapacity(self: *Self, item: T) void {281 pub fn appendReserved(self: *Self, item: T) void {
270 const new_item_ptr = self.addOneAssumeCapacity();282 const new_item_ptr = self.addOneReserved();
271 new_item_ptr.* = item;283 new_item_ptr.* = item;
272 }284 }
273285
...@@ -280,7 +292,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -280,7 +292,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
280 /// Asserts that the list is not empty.292 /// Asserts that the list is not empty.
281 pub fn orderedRemove(self: *Self, i: usize) T {293 pub fn orderedRemove(self: *Self, i: usize) T {
282 const old_item = self.items[i];294 const old_item = self.items[i];
283 self.replaceRangeAssumeCapacity(i, 1, &.{});295 self.replaceRangeReserved(i, 1, &.{});
284 return old_item;296 return old_item;
285 }297 }
286298
...@@ -303,13 +315,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -303,13 +315,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
303 /// Invalidates element pointers if additional memory is needed.315 /// Invalidates element pointers if additional memory is needed.
304 pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void {316 pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void {
305 try self.ensureUnusedCapacity(items.len);317 try self.ensureUnusedCapacity(items.len);
306 self.appendSliceAssumeCapacity(items);318 self.appendSliceReserved(items);
307 }319 }
308320
321 /// Deprecated. To be removed after 0.14.0 is tagged.
322 pub const appendSliceAssumeCapacity = appendSliceReserved;
323
309 /// Append the slice of items to the list.324 /// Append the slice of items to the list.
310 /// Never invalidates element pointers.325 /// Never invalidates element pointers.
311 /// Asserts that the list can hold the additional items.326 /// 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 {
313 const old_len = self.items.len;328 const old_len = self.items.len;
314 const new_len = old_len + items.len;329 const new_len = old_len + items.len;
315 assert(new_len <= self.capacity);330 assert(new_len <= self.capacity);
...@@ -323,16 +338,19 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -323,16 +338,19 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
323 /// Invalidates element pointers if additional memory is needed.338 /// Invalidates element pointers if additional memory is needed.
324 pub fn appendUnalignedSlice(self: *Self, items: []align(1) const T) Allocator.Error!void {339 pub fn appendUnalignedSlice(self: *Self, items: []align(1) const T) Allocator.Error!void {
325 try self.ensureUnusedCapacity(items.len);340 try self.ensureUnusedCapacity(items.len);
326 self.appendUnalignedSliceAssumeCapacity(items);341 self.appendUnalignedSliceReserved(items);
327 }342 }
328343
344 /// Deprecated. To be removed after 0.14.0 is tagged.
345 pub const appendUnalignedSliceAssumeCapacity = appendUnalignedSliceReserved;
346
329 /// Append the slice of items to the list.347 /// Append the slice of items to the list.
330 /// Never invalidates element pointers.348 /// Never invalidates element pointers.
331 /// This function is only needed when calling349 /// This function is only needed when calling
332 /// `appendSliceAssumeCapacity` instead would be a compile error due to the350 /// `appendSliceReserved` instead would be a compile error due to the
333 /// alignment of the `items` parameter.351 /// alignment of the `items` parameter.
334 /// Asserts that the list can hold the additional items.352 /// 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 {
336 const old_len = self.items.len;354 const old_len = self.items.len;
337 const new_len = old_len + items.len;355 const new_len = old_len + items.len;
338 assert(new_len <= self.capacity);356 assert(new_len <= self.capacity);
...@@ -373,7 +391,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -373,7 +391,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
373 if (m.len > available_capacity)391 if (m.len > available_capacity)
374 return error.OutOfMemory;392 return error.OutOfMemory;
375393
376 self.appendSliceAssumeCapacity(m);394 self.appendSliceReserved(m);
377 return m.len;395 return m.len;
378 }396 }
379397
...@@ -388,12 +406,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -388,12 +406,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
388 @memset(self.items[old_len..self.items.len], value);406 @memset(self.items[old_len..self.items.len], value);
389 }407 }
390408
409 /// Deprecated. To be removed after 0.14.0 is tagged.
410 pub const appendNTimesAssumeCapacity = appendNTimesReserved;
411
391 /// Append a value to the list `n` times.412 /// Append a value to the list `n` times.
392 /// Never invalidates element pointers.413 /// Never invalidates element pointers.
393 /// The function is inline so that a comptime-known `value` parameter will414 /// The function is inline so that a comptime-known `value` parameter will
394 /// have a more optimal memset codegen in case it has a repeated byte pattern.415 /// have a more optimal memset codegen in case it has a repeated byte pattern.
395 /// Asserts that the list can hold the additional items.416 /// 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 {
397 const new_len = self.items.len + n;418 const new_len = self.items.len + n;
398 assert(new_len <= self.capacity);419 assert(new_len <= self.capacity);
399 @memset(self.items.ptr[self.items.len..new_len], value);420 @memset(self.items.ptr[self.items.len..new_len], value);
...@@ -499,14 +520,17 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -499,14 +520,17 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
499 // This can never overflow because `self.items` can never occupy the whole address space520 // This can never overflow because `self.items` can never occupy the whole address space
500 const newlen = self.items.len + 1;521 const newlen = self.items.len + 1;
501 try self.ensureTotalCapacity(newlen);522 try self.ensureTotalCapacity(newlen);
502 return self.addOneAssumeCapacity();523 return self.addOneReserved();
503 }524 }
504525
526 /// Deprecated. To be removed after 0.14.0 is tagged.
527 pub const addOneAssumeCapacity = addOneReserved;
528
505 /// Increase length by 1, returning pointer to the new item.529 /// Increase length by 1, returning pointer to the new item.
506 /// The returned pointer becomes invalid when the list is resized.530 /// The returned pointer becomes invalid when the list is resized.
507 /// Never invalidates element pointers.531 /// Never invalidates element pointers.
508 /// Asserts that the list can hold one additional item.532 /// Asserts that the list can hold one additional item.
509 pub fn addOneAssumeCapacity(self: *Self) *T {533 pub fn addOneReserved(self: *Self) *T {
510 assert(self.items.len < self.capacity);534 assert(self.items.len < self.capacity);
511 self.items.len += 1;535 self.items.len += 1;
512 return &self.items[self.items.len - 1];536 return &self.items[self.items.len - 1];
...@@ -522,12 +546,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -522,12 +546,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
522 return self.items[prev_len..][0..n];546 return self.items[prev_len..][0..n];
523 }547 }
524548
549 /// Deprecated. To be removed after 0.14.0 is tagged.
550 pub const addManyAsArrayAssumeCapacity = addManyAsArrayReserved;
551
525 /// Resize the array, adding `n` new elements, which have `undefined` values.552 /// Resize the array, adding `n` new elements, which have `undefined` values.
526 /// The return value is an array pointing to the newly allocated elements.553 /// The return value is an array pointing to the newly allocated elements.
527 /// Never invalidates element pointers.554 /// Never invalidates element pointers.
528 /// The returned pointer becomes invalid when the list is resized.555 /// The returned pointer becomes invalid when the list is resized.
529 /// Asserts that the list can hold the additional items.556 /// 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 {
531 assert(self.items.len + n <= self.capacity);558 assert(self.items.len + n <= self.capacity);
532 const prev_len = self.items.len;559 const prev_len = self.items.len;
533 self.items.len += n;560 self.items.len += n;
...@@ -544,12 +571,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -544,12 +571,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
544 return self.items[prev_len..][0..n];571 return self.items[prev_len..][0..n];
545 }572 }
546573
574 /// Deprecated. To be removed after 0.14.0 is tagged.
575 pub const addManyAsSliceAssumeCapacity = addManyAsSliceReserved;
576
547 /// Resize the array, adding `n` new elements, which have `undefined` values.577 /// Resize the array, adding `n` new elements, which have `undefined` values.
548 /// The return value is a slice pointing to the newly allocated elements.578 /// The return value is a slice pointing to the newly allocated elements.
549 /// Never invalidates element pointers.579 /// Never invalidates element pointers.
550 /// The returned pointer becomes invalid when the list is resized.580 /// The returned pointer becomes invalid when the list is resized.
551 /// Asserts that the list can hold the additional items.581 /// 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 {
553 assert(self.items.len + n <= self.capacity);583 assert(self.items.len + n <= self.capacity);
554 const prev_len = self.items.len;584 const prev_len = self.items.len;
555 self.items.len += n;585 self.items.len += n;
...@@ -725,7 +755,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -725,7 +755,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
725 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {755 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
726 // This addition can never overflow because `self.items` can never occupy the whole address space756 // This addition can never overflow because `self.items` can never occupy the whole address space
727 try self.ensureTotalCapacityPrecise(allocator, self.items.len + 1);757 try self.ensureTotalCapacityPrecise(allocator, self.items.len + 1);
728 self.appendAssumeCapacity(sentinel);758 self.appendReserved(sentinel);
729 const result = try self.toOwnedSlice(allocator);759 const result = try self.toOwnedSlice(allocator);
730 return result[0 .. result.len - 1 :sentinel];760 return result[0 .. result.len - 1 :sentinel];
731 }761 }
...@@ -733,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -733,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
733 /// Creates a copy of this ArrayList.763 /// Creates a copy of this ArrayList.
734 pub fn clone(self: Self, allocator: Allocator) Allocator.Error!Self {764 pub fn clone(self: Self, allocator: Allocator) Allocator.Error!Self {
735 var cloned = try Self.initCapacity(allocator, self.capacity);765 var cloned = try Self.initCapacity(allocator, self.capacity);
736 cloned.appendSliceAssumeCapacity(self.items);766 cloned.appendSliceReserved(self.items);
737 return cloned;767 return cloned;
738 }768 }
739769
...@@ -747,12 +777,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -747,12 +777,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
747 dst[0] = item;777 dst[0] = item;
748 }778 }
749779
780 /// Deprecated. To be removed after 0.14.0 is tagged.
781 pub const insertAssumeCapacity = insertReserved;
782
750 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.783 /// Insert `item` at index `i`. Moves `list[i .. list.len]` to higher indices to make room.
751 /// If in` is equal to the length of the list this operation is equivalent to append.784 /// If in` is equal to the length of the list this operation is equivalent to append.
752 /// This operation is O(N).785 /// This operation is O(N).
753 /// Asserts that the list has capacity for one additional item.786 /// Asserts that the list has capacity for one additional item.
754 /// Asserts that the index is in bounds or equal to the length.787 /// 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 {
756 assert(self.items.len < self.capacity);789 assert(self.items.len < self.capacity);
757 self.items.len += 1;790 self.items.len += 1;
758791
...@@ -779,6 +812,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -779,6 +812,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
779 return managed.addManyAt(index, count);812 return managed.addManyAt(index, count);
780 }813 }
781814
815 /// Deprecated. To be removed after 0.14.0 is tagged.
816 pub const addManyAtAssumeCapacity = addManyAtReserved;
817
782 /// Add `count` new elements at position `index`, which have818 /// Add `count` new elements at position `index`, which have
783 /// `undefined` values. Returns a slice pointing to the newly allocated819 /// `undefined` values. Returns a slice pointing to the newly allocated
784 /// elements, which becomes invalid after various `ArrayList`820 /// elements, which becomes invalid after various `ArrayList`
...@@ -787,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -787,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
787 /// does not invalidate any before that.823 /// does not invalidate any before that.
788 /// Asserts that the list has capacity for the additional items.824 /// Asserts that the list has capacity for the additional items.
789 /// Asserts that the index is in bounds or equal to the length.825 /// 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 {
791 const new_len = self.items.len + count;827 const new_len = self.items.len + count;
792 assert(self.capacity >= new_len);828 assert(self.capacity >= new_len);
793 const to_move = self.items[index..];829 const to_move = self.items[index..];
...@@ -836,14 +872,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -836,14 +872,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
836 @memcpy(range[0..first.len], first);872 @memcpy(range[0..first.len], first);
837 try self.insertSlice(allocator, after_range, rest);873 try self.insertSlice(allocator, after_range, rest);
838 } else {874 } else {
839 self.replaceRangeAssumeCapacity(start, len, new_items);875 self.replaceRangeReserved(start, len, new_items);
840 }876 }
841 }877 }
842878
879 /// Deprecated. To be removed after 0.14.0 is tagged.
880 pub const replaceRangeAssumeCapacity = replaceRangeReserved;
881
843 /// Grows or shrinks the list as necessary.882 /// Grows or shrinks the list as necessary.
844 /// Never invalidates element pointers.883 /// Never invalidates element pointers.
845 /// Asserts the capacity is enough for additional items.884 /// 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 {
847 const after_range = start + len;886 const after_range = start + len;
848 const range = self.items[start..after_range];887 const range = self.items[start..after_range];
849888
...@@ -853,7 +892,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -853,7 +892,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
853 const first = new_items[0..range.len];892 const first = new_items[0..range.len];
854 const rest = new_items[range.len..];893 const rest = new_items[range.len..];
855 @memcpy(range[0..first.len], first);894 @memcpy(range[0..first.len], first);
856 const dst = self.addManyAtAssumeCapacity(after_range, rest.len);895 const dst = self.addManyAtReserved(after_range, rest.len);
857 @memcpy(dst, rest);896 @memcpy(dst, rest);
858 } else {897 } else {
859 const extra = range.len - new_items.len;898 const extra = range.len - new_items.len;
...@@ -875,11 +914,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -875,11 +914,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
875 new_item_ptr.* = item;914 new_item_ptr.* = item;
876 }915 }
877916
917 /// Deprecated. To be removed after 0.14.0 is tagged.
918 pub const appendAssumeCapacity = appendReserved;
919
878 /// Extend the list by 1 element.920 /// Extend the list by 1 element.
879 /// Never invalidates element pointers.921 /// Never invalidates element pointers.
880 /// Asserts that the list can hold one additional item.922 /// Asserts that the list can hold one additional item.
881 pub fn appendAssumeCapacity(self: *Self, item: T) void {923 pub fn appendReserved(self: *Self, item: T) void {
882 const new_item_ptr = self.addOneAssumeCapacity();924 const new_item_ptr = self.addOneReserved();
883 new_item_ptr.* = item;925 new_item_ptr.* = item;
884 }926 }
885927
...@@ -890,7 +932,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -890,7 +932,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
890 /// Asserts that the index is in bounds.932 /// Asserts that the index is in bounds.
891 pub fn orderedRemove(self: *Self, i: usize) T {933 pub fn orderedRemove(self: *Self, i: usize) T {
892 const old_item = self.items[i];934 const old_item = self.items[i];
893 self.replaceRangeAssumeCapacity(i, 1, &.{});935 self.replaceRangeReserved(i, 1, &.{});
894 return old_item;936 return old_item;
895 }937 }
896938
...@@ -913,12 +955,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -913,12 +955,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
913 /// Invalidates element pointers if additional memory is needed.955 /// Invalidates element pointers if additional memory is needed.
914 pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void {956 pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void {
915 try self.ensureUnusedCapacity(allocator, items.len);957 try self.ensureUnusedCapacity(allocator, items.len);
916 self.appendSliceAssumeCapacity(items);958 self.appendSliceReserved(items);
917 }959 }
918960
961 /// Deprecated. To be removed after 0.14.0 is tagged.
962 pub const appendSliceAssumeCapacity = appendSliceReserved;
963
919 /// Append the slice of items to the list.964 /// Append the slice of items to the list.
920 /// Asserts that the list can hold the additional items.965 /// 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 {
922 const old_len = self.items.len;967 const old_len = self.items.len;
923 const new_len = old_len + items.len;968 const new_len = old_len + items.len;
924 assert(new_len <= self.capacity);969 assert(new_len <= self.capacity);
...@@ -932,14 +977,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -932,14 +977,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
932 /// Invalidates element pointers if additional memory is needed.977 /// Invalidates element pointers if additional memory is needed.
933 pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void {978 pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void {
934 try self.ensureUnusedCapacity(allocator, items.len);979 try self.ensureUnusedCapacity(allocator, items.len);
935 self.appendUnalignedSliceAssumeCapacity(items);980 self.appendUnalignedSliceReserved(items);
936 }981 }
937982
983 /// Deprecated. To be removed after 0.14.0 is tagged.
984 pub const appendUnalignedSliceAssumeCapacity = appendUnalignedSliceReserved;
985
938 /// Append an unaligned slice of items to the list.986 /// 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`
940 /// instead would be a compile error.988 /// instead would be a compile error.
941 /// Asserts that the list can hold the additional items.989 /// 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 {
943 const old_len = self.items.len;991 const old_len = self.items.len;
944 const new_len = old_len + items.len;992 const new_len = old_len + items.len;
945 assert(new_len <= self.capacity);993 assert(new_len <= self.capacity);
...@@ -986,7 +1034,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -986,7 +1034,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
986 if (m.len > available_capacity)1034 if (m.len > available_capacity)
987 return error.OutOfMemory;1035 return error.OutOfMemory;
9881036
989 self.appendSliceAssumeCapacity(m);1037 self.appendSliceReserved(m);
990 return m.len;1038 return m.len;
991 }1039 }
9921040
...@@ -1006,7 +1054,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1006,7 +1054,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1006 /// The function is inline so that a comptime-known `value` parameter will1054 /// The function is inline so that a comptime-known `value` parameter will
1007 /// have better memset codegen in case it has a repeated byte pattern.1055 /// have better memset codegen in case it has a repeated byte pattern.
1008 /// Asserts that the list can hold the additional items.1056 /// 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 {
1010 const new_len = self.items.len + n;1058 const new_len = self.items.len + n;
1011 assert(new_len <= self.capacity);1059 assert(new_len <= self.capacity);
1012 @memset(self.items.ptr[self.items.len..new_len], value);1060 @memset(self.items.ptr[self.items.len..new_len], value);
...@@ -1135,14 +1183,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1135,14 +1183,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1135 // This can never overflow because `self.items` can never occupy the whole address space1183 // This can never overflow because `self.items` can never occupy the whole address space
1136 const newlen = self.items.len + 1;1184 const newlen = self.items.len + 1;
1137 try self.ensureTotalCapacity(allocator, newlen);1185 try self.ensureTotalCapacity(allocator, newlen);
1138 return self.addOneAssumeCapacity();1186 return self.addOneReserved();
1139 }1187 }
11401188
1189 /// Deprecated. To be removed after 0.14.0 is tagged.
1190 pub const addOneAssumeCapacity = addOneReserved;
1191
1141 /// Increase length by 1, returning pointer to the new item.1192 /// Increase length by 1, returning pointer to the new item.
1142 /// Never invalidates element pointers.1193 /// Never invalidates element pointers.
1143 /// The returned element pointer becomes invalid when the list is resized.1194 /// The returned element pointer becomes invalid when the list is resized.
1144 /// Asserts that the list can hold one additional item.1195 /// Asserts that the list can hold one additional item.
1145 pub fn addOneAssumeCapacity(self: *Self) *T {1196 pub fn addOneReserved(self: *Self) *T {
1146 assert(self.items.len < self.capacity);1197 assert(self.items.len < self.capacity);
11471198
1148 self.items.len += 1;1199 self.items.len += 1;
...@@ -1158,12 +1209,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1158,12 +1209,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1158 return self.items[prev_len..][0..n];1209 return self.items[prev_len..][0..n];
1159 }1210 }
11601211
1212 /// Deprecated. To be removed after 0.14.0 is tagged.
1213 pub const addManyAsArrayAssumeCapacity = addManyAsArrayReserved;
1214
1161 /// Resize the array, adding `n` new elements, which have `undefined` values.1215 /// Resize the array, adding `n` new elements, which have `undefined` values.
1162 /// The return value is an array pointing to the newly allocated elements.1216 /// The return value is an array pointing to the newly allocated elements.
1163 /// Never invalidates element pointers.1217 /// Never invalidates element pointers.
1164 /// The returned pointer becomes invalid when the list is resized.1218 /// The returned pointer becomes invalid when the list is resized.
1165 /// Asserts that the list can hold the additional items.1219 /// 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 {
1167 assert(self.items.len + n <= self.capacity);1221 assert(self.items.len + n <= self.capacity);
1168 const prev_len = self.items.len;1222 const prev_len = self.items.len;
1169 self.items.len += n;1223 self.items.len += n;
...@@ -1180,12 +1234,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1180,12 +1234,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1180 return self.items[prev_len..][0..n];1234 return self.items[prev_len..][0..n];
1181 }1235 }
11821236
1237 /// Deprecated. To be removed after 0.14.0 is tagged.
1238 pub const addManyAsSliceAssumeCapacity = addManyAsSliceReserved;
1239
1183 /// Resize the array, adding `n` new elements, which have `undefined` values.1240 /// Resize the array, adding `n` new elements, which have `undefined` values.
1184 /// The return value is a slice pointing to the newly allocated elements.1241 /// The return value is a slice pointing to the newly allocated elements.
1185 /// Never invalidates element pointers.1242 /// Never invalidates element pointers.
1186 /// The returned pointer becomes invalid when the list is resized.1243 /// The returned pointer becomes invalid when the list is resized.
1187 /// Asserts that the list can hold the additional items.1244 /// 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 {
1189 assert(self.items.len + n <= self.capacity);1246 assert(self.items.len + n <= self.capacity);
1190 const prev_len = self.items.len;1247 const prev_len = self.items.len;
1191 self.items.len += n;1248 self.items.len += n;
...@@ -1731,7 +1788,7 @@ test "ArrayList.replaceRange" {...@@ -1731,7 +1788,7 @@ test "ArrayList.replaceRange" {
1731 }1788 }
1732}1789}
17331790
1734test "ArrayList.replaceRangeAssumeCapacity" {1791test "ArrayList.replaceRangeReserved" {
1735 const a = testing.allocator;1792 const a = testing.allocator;
17361793
1737 {1794 {
...@@ -1739,7 +1796,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {...@@ -1739,7 +1796,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
1739 defer list.deinit();1796 defer list.deinit();
1740 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });1797 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
1744 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);1801 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);
1745 }1802 }
...@@ -1748,7 +1805,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {...@@ -1748,7 +1805,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
1748 defer list.deinit();1805 defer list.deinit();
1749 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });1806 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
1753 try testing.expectEqualSlices(1810 try testing.expectEqualSlices(
1754 i32,1811 i32,
...@@ -1761,7 +1818,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {...@@ -1761,7 +1818,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
1761 defer list.deinit();1818 defer list.deinit();
1762 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });1819 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
1766 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);1823 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);
1767 }1824 }
...@@ -1770,7 +1827,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {...@@ -1770,7 +1827,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
1770 defer list.deinit();1827 defer list.deinit();
1771 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });1828 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
1775 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);1832 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);
1776 }1833 }
...@@ -1779,7 +1836,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {...@@ -1779,7 +1836,7 @@ test "ArrayList.replaceRangeAssumeCapacity" {
1779 defer list.deinit();1836 defer list.deinit();
1780 try list.appendSlice(&[_]i32{ 1, 2, 3, 4, 5 });1837 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
1784 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);1841 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);
1785 }1842 }
...@@ -1839,7 +1896,7 @@ test "ArrayListUnmanaged.replaceRange" {...@@ -1839,7 +1896,7 @@ test "ArrayListUnmanaged.replaceRange" {
1839 }1896 }
1840}1897}
18411898
1842test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {1899test "ArrayListUnmanaged.replaceRangeReserved" {
1843 const a = testing.allocator;1900 const a = testing.allocator;
18441901
1845 {1902 {
...@@ -1847,7 +1904,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {...@@ -1847,7 +1904,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1847 defer list.deinit(a);1904 defer list.deinit(a);
1848 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });1905 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
1852 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);1909 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 2, 3, 4, 5 }, list.items);
1853 }1910 }
...@@ -1856,7 +1913,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {...@@ -1856,7 +1913,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1856 defer list.deinit(a);1913 defer list.deinit(a);
1857 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });1914 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
1861 try testing.expectEqualSlices(1918 try testing.expectEqualSlices(
1862 i32,1919 i32,
...@@ -1869,7 +1926,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {...@@ -1869,7 +1926,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1869 defer list.deinit(a);1926 defer list.deinit(a);
1870 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });1927 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
1874 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);1931 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 4, 5 }, list.items);
1875 }1932 }
...@@ -1878,7 +1935,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {...@@ -1878,7 +1935,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1878 defer list.deinit(a);1935 defer list.deinit(a);
1879 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });1936 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
1883 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);1940 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0, 5 }, list.items);
1884 }1941 }
...@@ -1887,7 +1944,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {...@@ -1887,7 +1944,7 @@ test "ArrayListUnmanaged.replaceRangeAssumeCapacity" {
1887 defer list.deinit(a);1944 defer list.deinit(a);
1888 try list.appendSlice(a, &[_]i32{ 1, 2, 3, 4, 5 });1945 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
1892 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);1949 try testing.expectEqualSlices(i32, &[_]i32{ 1, 0, 0, 0 }, list.items);
1893 }1950 }
...@@ -2021,7 +2078,7 @@ test "addManyAsArray" {...@@ -2021,7 +2078,7 @@ test "addManyAsArray" {
20212078
2022 (try list.addManyAsArray(4)).* = "aoeu".*;2079 (try list.addManyAsArray(4)).* = "aoeu".*;
2023 try list.ensureTotalCapacity(8);2080 try list.ensureTotalCapacity(8);
2024 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;2081 list.addManyAsArrayReserved(4).* = "asdf".*;
20252082
2026 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");2083 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
2027 }2084 }
...@@ -2031,7 +2088,7 @@ test "addManyAsArray" {...@@ -2031,7 +2088,7 @@ test "addManyAsArray" {
20312088
2032 (try list.addManyAsArray(a, 4)).* = "aoeu".*;2089 (try list.addManyAsArray(a, 4)).* = "aoeu".*;
2033 try list.ensureTotalCapacity(a, 8);2090 try list.ensureTotalCapacity(a, 8);
2034 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;2091 list.addManyAsArrayReserved(4).* = "asdf".*;
20352092
2036 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");2093 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
2037 }2094 }