authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2022-02-20 11:39:51+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-22 13:57:51-05:00
loge620b692c6c9f7c4b655f30aae5e51a87dc56e91
tree167716eba59152d2348e8732fb408d50ab54ca56
parentdf38c46bee9a54b9935f2e3372f6b86299730888

[std.ArrayList] return explicit errors

All errors from std.ArrayList are allocation errors. Mark them as such. This is helpful when one wants to obtain a function pointer.

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

lib/std/array_list.zig+32-32
...@@ -58,7 +58,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -58,7 +58,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
58 /// Initialize with capacity to hold at least `num` elements.58 /// Initialize with capacity to hold at least `num` elements.
59 /// The resulting capacity is likely to be equal to `num`.59 /// The resulting capacity is likely to be equal to `num`.
60 /// Deinitialize with `deinit` or use `toOwnedSlice`.60 /// Deinitialize with `deinit` or use `toOwnedSlice`.
61 pub fn initCapacity(allocator: Allocator, num: usize) !Self {61 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
62 var self = Self.init(allocator);62 var self = Self.init(allocator);
63 try self.ensureTotalCapacityPrecise(num);63 try self.ensureTotalCapacityPrecise(num);
64 return self;64 return self;
...@@ -102,14 +102,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -102,14 +102,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
102 }102 }
103103
104 /// The caller owns the returned memory. Empties this ArrayList.104 /// The caller owns the returned memory. Empties this ArrayList.
105 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) ![:sentinel]T {105 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error![:sentinel]T {
106 try self.append(sentinel);106 try self.append(sentinel);
107 const result = self.toOwnedSlice();107 const result = self.toOwnedSlice();
108 return result[0 .. result.len - 1 :sentinel];108 return result[0 .. result.len - 1 :sentinel];
109 }109 }
110110
111 /// Creates a copy of this ArrayList, using the same allocator.111 /// Creates a copy of this ArrayList, using the same allocator.
112 pub fn clone(self: *Self) !Self {112 pub fn clone(self: *Self) Allocator.Error!Self {
113 var cloned = try Self.initCapacity(self.allocator, self.capacity);113 var cloned = try Self.initCapacity(self.allocator, self.capacity);
114 cloned.appendSliceAssumeCapacity(self.items);114 cloned.appendSliceAssumeCapacity(self.items);
115 return cloned;115 return cloned;
...@@ -117,7 +117,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -117,7 +117,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
117117
118 /// Insert `item` at index `n` by moving `list[n .. list.len]` to make room.118 /// Insert `item` at index `n` by moving `list[n .. list.len]` to make room.
119 /// This operation is O(N).119 /// This operation is O(N).
120 pub fn insert(self: *Self, n: usize, item: T) !void {120 pub fn insert(self: *Self, n: usize, item: T) Allocator.Error!void {
121 try self.ensureUnusedCapacity(1);121 try self.ensureUnusedCapacity(1);
122 self.items.len += 1;122 self.items.len += 1;
123123
...@@ -127,7 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -127,7 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
127127
128 /// Insert slice `items` at index `i` by moving `list[i .. list.len]` to make room.128 /// Insert slice `items` at index `i` by moving `list[i .. list.len]` to make room.
129 /// This operation is O(N).129 /// This operation is O(N).
130 pub fn insertSlice(self: *Self, i: usize, items: []const T) !void {130 pub fn insertSlice(self: *Self, i: usize, items: []const T) Allocator.Error!void {
131 try self.ensureUnusedCapacity(items.len);131 try self.ensureUnusedCapacity(items.len);
132 self.items.len += items.len;132 self.items.len += items.len;
133133
...@@ -139,7 +139,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -139,7 +139,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
139 /// Grows list if `len < new_items.len`.139 /// Grows list if `len < new_items.len`.
140 /// Shrinks list if `len > new_items.len`.140 /// Shrinks list if `len > new_items.len`.
141 /// Invalidates pointers if this ArrayList is resized.141 /// Invalidates pointers if this ArrayList is resized.
142 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) !void {142 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
143 const after_range = start + len;143 const after_range = start + len;
144 const range = self.items[start..after_range];144 const range = self.items[start..after_range];
145145
...@@ -164,7 +164,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -164,7 +164,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
164 }164 }
165165
166 /// Extend the list by 1 element. Allocates more memory as necessary.166 /// Extend the list by 1 element. Allocates more memory as necessary.
167 pub fn append(self: *Self, item: T) !void {167 pub fn append(self: *Self, item: T) Allocator.Error!void {
168 const new_item_ptr = try self.addOne();168 const new_item_ptr = try self.addOne();
169 new_item_ptr.* = item;169 new_item_ptr.* = item;
170 }170 }
...@@ -206,7 +206,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -206,7 +206,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
206206
207 /// Append the slice of items to the list. Allocates more207 /// Append the slice of items to the list. Allocates more
208 /// memory as necessary.208 /// memory as necessary.
209 pub fn appendSlice(self: *Self, items: []const T) !void {209 pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void {
210 try self.ensureUnusedCapacity(items.len);210 try self.ensureUnusedCapacity(items.len);
211 self.appendSliceAssumeCapacity(items);211 self.appendSliceAssumeCapacity(items);
212 }212 }
...@@ -234,14 +234,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -234,14 +234,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
234234
235 /// Same as `append` except it returns the number of bytes written, which is always the same235 /// Same as `append` except it returns the number of bytes written, which is always the same
236 /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API.236 /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API.
237 fn appendWrite(self: *Self, m: []const u8) !usize {237 fn appendWrite(self: *Self, m: []const u8) Allocator.Error!usize {
238 try self.appendSlice(m);238 try self.appendSlice(m);
239 return m.len;239 return m.len;
240 }240 }
241241
242 /// Append a value to the list `n` times.242 /// Append a value to the list `n` times.
243 /// Allocates more memory as necessary.243 /// Allocates more memory as necessary.
244 pub fn appendNTimes(self: *Self, value: T, n: usize) !void {244 pub fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void {
245 const old_len = self.items.len;245 const old_len = self.items.len;
246 try self.resize(self.items.len + n);246 try self.resize(self.items.len + n);
247 mem.set(T, self.items[old_len..self.items.len], value);247 mem.set(T, self.items[old_len..self.items.len], value);
...@@ -258,7 +258,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -258,7 +258,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
258258
259 /// Adjust the list's length to `new_len`.259 /// Adjust the list's length to `new_len`.
260 /// Does not initialize added items if any.260 /// Does not initialize added items if any.
261 pub fn resize(self: *Self, new_len: usize) !void {261 pub fn resize(self: *Self, new_len: usize) Allocator.Error!void {
262 try self.ensureTotalCapacity(new_len);262 try self.ensureTotalCapacity(new_len);
263 self.items.len = new_len;263 self.items.len = new_len;
264 }264 }
...@@ -304,7 +304,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -304,7 +304,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
304304
305 /// Modify the array so that it can hold at least `new_capacity` items.305 /// Modify the array so that it can hold at least `new_capacity` items.
306 /// Invalidates pointers if additional memory is needed.306 /// Invalidates pointers if additional memory is needed.
307 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {307 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) Allocator.Error!void {
308 if (@sizeOf(T) > 0) {308 if (@sizeOf(T) > 0) {
309 var better_capacity = self.capacity;309 var better_capacity = self.capacity;
310 if (better_capacity >= new_capacity) return;310 if (better_capacity >= new_capacity) return;
...@@ -324,7 +324,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -324,7 +324,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
324 /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely324 /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely
325 /// (but not guaranteed) to be equal to `new_capacity`.325 /// (but not guaranteed) to be equal to `new_capacity`.
326 /// Invalidates pointers if additional memory is needed.326 /// Invalidates pointers if additional memory is needed.
327 pub fn ensureTotalCapacityPrecise(self: *Self, new_capacity: usize) !void {327 pub fn ensureTotalCapacityPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {
328 if (@sizeOf(T) > 0) {328 if (@sizeOf(T) > 0) {
329 if (self.capacity >= new_capacity) return;329 if (self.capacity >= new_capacity) return;
330330
...@@ -339,7 +339,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -339,7 +339,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
339339
340 /// Modify the array so that it can hold at least `additional_count` **more** items.340 /// Modify the array so that it can hold at least `additional_count` **more** items.
341 /// Invalidates pointers if additional memory is needed.341 /// Invalidates pointers if additional memory is needed.
342 pub fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void {342 pub fn ensureUnusedCapacity(self: *Self, additional_count: usize) Allocator.Error!void {
343 return self.ensureTotalCapacity(self.items.len + additional_count);343 return self.ensureTotalCapacity(self.items.len + additional_count);
344 }344 }
345345
...@@ -351,7 +351,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -351,7 +351,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
351351
352 /// Increase length by 1, returning pointer to the new item.352 /// Increase length by 1, returning pointer to the new item.
353 /// The returned pointer becomes invalid when the list resized.353 /// The returned pointer becomes invalid when the list resized.
354 pub fn addOne(self: *Self) !*T {354 pub fn addOne(self: *Self) Allocator.Error!*T {
355 const newlen = self.items.len + 1;355 const newlen = self.items.len + 1;
356 try self.ensureTotalCapacity(newlen);356 try self.ensureTotalCapacity(newlen);
357 return self.addOneAssumeCapacity();357 return self.addOneAssumeCapacity();
...@@ -372,7 +372,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -372,7 +372,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
372 /// The return value is an array pointing to the newly allocated elements.372 /// The return value is an array pointing to the newly allocated elements.
373 /// The returned pointer becomes invalid when the list is resized.373 /// The returned pointer becomes invalid when the list is resized.
374 /// Resizes list if `self.capacity` is not large enough.374 /// Resizes list if `self.capacity` is not large enough.
375 pub fn addManyAsArray(self: *Self, comptime n: usize) !*[n]T {375 pub fn addManyAsArray(self: *Self, comptime n: usize) Allocator.Error!*[n]T {
376 const prev_len = self.items.len;376 const prev_len = self.items.len;
377 try self.resize(self.items.len + n);377 try self.resize(self.items.len + n);
378 return self.items[prev_len..][0..n];378 return self.items[prev_len..][0..n];
...@@ -464,7 +464,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -464,7 +464,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
464 /// Initialize with capacity to hold at least num elements.464 /// Initialize with capacity to hold at least num elements.
465 /// The resulting capacity is likely to be equal to `num`.465 /// The resulting capacity is likely to be equal to `num`.
466 /// Deinitialize with `deinit` or use `toOwnedSlice`.466 /// Deinitialize with `deinit` or use `toOwnedSlice`.
467 pub fn initCapacity(allocator: Allocator, num: usize) !Self {467 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
468 var self = Self{};468 var self = Self{};
469 try self.ensureTotalCapacityPrecise(allocator, num);469 try self.ensureTotalCapacityPrecise(allocator, num);
470 return self;470 return self;
...@@ -490,14 +490,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -490,14 +490,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
490 }490 }
491491
492 /// The caller owns the returned memory. ArrayList becomes empty.492 /// The caller owns the returned memory. ArrayList becomes empty.
493 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) ![:sentinel]T {493 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error![:sentinel]T {
494 try self.append(allocator, sentinel);494 try self.append(allocator, sentinel);
495 const result = self.toOwnedSlice(allocator);495 const result = self.toOwnedSlice(allocator);
496 return result[0 .. result.len - 1 :sentinel];496 return result[0 .. result.len - 1 :sentinel];
497 }497 }
498498
499 /// Creates a copy of this ArrayList.499 /// Creates a copy of this ArrayList.
500 pub fn clone(self: *Self, allocator: Allocator) !Self {500 pub fn clone(self: *Self, allocator: Allocator) Allocator.Error!Self {
501 var cloned = try Self.initCapacity(allocator, self.capacity);501 var cloned = try Self.initCapacity(allocator, self.capacity);
502 cloned.appendSliceAssumeCapacity(self.items);502 cloned.appendSliceAssumeCapacity(self.items);
503 return cloned;503 return cloned;
...@@ -506,7 +506,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -506,7 +506,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
506 /// Insert `item` at index `n`. Moves `list[n .. list.len]`506 /// Insert `item` at index `n`. Moves `list[n .. list.len]`
507 /// to higher indices to make room.507 /// to higher indices to make room.
508 /// This operation is O(N).508 /// This operation is O(N).
509 pub fn insert(self: *Self, allocator: Allocator, n: usize, item: T) !void {509 pub fn insert(self: *Self, allocator: Allocator, n: usize, item: T) Allocator.Error!void {
510 try self.ensureUnusedCapacity(allocator, 1);510 try self.ensureUnusedCapacity(allocator, 1);
511 self.items.len += 1;511 self.items.len += 1;
512512
...@@ -517,7 +517,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -517,7 +517,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
517 /// Insert slice `items` at index `i`. Moves `list[i .. list.len]` to517 /// Insert slice `items` at index `i`. Moves `list[i .. list.len]` to
518 /// higher indicices make room.518 /// higher indicices make room.
519 /// This operation is O(N).519 /// This operation is O(N).
520 pub fn insertSlice(self: *Self, allocator: Allocator, i: usize, items: []const T) !void {520 pub fn insertSlice(self: *Self, allocator: Allocator, i: usize, items: []const T) Allocator.Error!void {
521 try self.ensureUnusedCapacity(allocator, items.len);521 try self.ensureUnusedCapacity(allocator, items.len);
522 self.items.len += items.len;522 self.items.len += items.len;
523523
...@@ -529,14 +529,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -529,14 +529,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
529 /// Grows list if `len < new_items.len`.529 /// Grows list if `len < new_items.len`.
530 /// Shrinks list if `len > new_items.len`530 /// Shrinks list if `len > new_items.len`
531 /// Invalidates pointers if this ArrayList is resized.531 /// Invalidates pointers if this ArrayList is resized.
532 pub fn replaceRange(self: *Self, allocator: Allocator, start: usize, len: usize, new_items: []const T) !void {532 pub fn replaceRange(self: *Self, allocator: Allocator, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
533 var managed = self.toManaged(allocator);533 var managed = self.toManaged(allocator);
534 try managed.replaceRange(start, len, new_items);534 try managed.replaceRange(start, len, new_items);
535 self.* = managed.moveToUnmanaged();535 self.* = managed.moveToUnmanaged();
536 }536 }
537537
538 /// Extend the list by 1 element. Allocates more memory as necessary.538 /// Extend the list by 1 element. Allocates more memory as necessary.
539 pub fn append(self: *Self, allocator: Allocator, item: T) !void {539 pub fn append(self: *Self, allocator: Allocator, item: T) Allocator.Error!void {
540 const new_item_ptr = try self.addOne(allocator);540 const new_item_ptr = try self.addOne(allocator);
541 new_item_ptr.* = item;541 new_item_ptr.* = item;
542 }542 }
...@@ -577,7 +577,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -577,7 +577,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
577577
578 /// Append the slice of items to the list. Allocates more578 /// Append the slice of items to the list. Allocates more
579 /// memory as necessary.579 /// memory as necessary.
580 pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) !void {580 pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void {
581 try self.ensureUnusedCapacity(allocator, items.len);581 try self.ensureUnusedCapacity(allocator, items.len);
582 self.appendSliceAssumeCapacity(items);582 self.appendSliceAssumeCapacity(items);
583 }583 }
...@@ -610,14 +610,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -610,14 +610,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
610610
611 /// Same as `append` except it returns the number of bytes written, which is always the same611 /// Same as `append` except it returns the number of bytes written, which is always the same
612 /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API.612 /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API.
613 fn appendWrite(context: WriterContext, m: []const u8) !usize {613 fn appendWrite(context: WriterContext, m: []const u8) Allocator.Error!usize {
614 try context.self.appendSlice(context.allocator, m);614 try context.self.appendSlice(context.allocator, m);
615 return m.len;615 return m.len;
616 }616 }
617617
618 /// Append a value to the list `n` times.618 /// Append a value to the list `n` times.
619 /// Allocates more memory as necessary.619 /// Allocates more memory as necessary.
620 pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) !void {620 pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void {
621 const old_len = self.items.len;621 const old_len = self.items.len;
622 try self.resize(allocator, self.items.len + n);622 try self.resize(allocator, self.items.len + n);
623 mem.set(T, self.items[old_len..self.items.len], value);623 mem.set(T, self.items[old_len..self.items.len], value);
...@@ -635,7 +635,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -635,7 +635,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
635635
636 /// Adjust the list's length to `new_len`.636 /// Adjust the list's length to `new_len`.
637 /// Does not initialize added items, if any.637 /// Does not initialize added items, if any.
638 pub fn resize(self: *Self, allocator: Allocator, new_len: usize) !void {638 pub fn resize(self: *Self, allocator: Allocator, new_len: usize) Allocator.Error!void {
639 try self.ensureTotalCapacity(allocator, new_len);639 try self.ensureTotalCapacity(allocator, new_len);
640 self.items.len = new_len;640 self.items.len = new_len;
641 }641 }
...@@ -677,7 +677,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -677,7 +677,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
677677
678 /// Modify the array so that it can hold at least `new_capacity` items.678 /// Modify the array so that it can hold at least `new_capacity` items.
679 /// Invalidates pointers if additional memory is needed.679 /// Invalidates pointers if additional memory is needed.
680 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) !void {680 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
681 var better_capacity = self.capacity;681 var better_capacity = self.capacity;
682 if (better_capacity >= new_capacity) return;682 if (better_capacity >= new_capacity) return;
683683
...@@ -693,7 +693,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -693,7 +693,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
693 /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely693 /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely
694 /// (but not guaranteed) to be equal to `new_capacity`.694 /// (but not guaranteed) to be equal to `new_capacity`.
695 /// Invalidates pointers if additional memory is needed.695 /// Invalidates pointers if additional memory is needed.
696 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) !void {696 pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
697 if (self.capacity >= new_capacity) return;697 if (self.capacity >= new_capacity) return;
698698
699 const new_memory = try allocator.reallocAtLeast(self.allocatedSlice(), new_capacity);699 const new_memory = try allocator.reallocAtLeast(self.allocatedSlice(), new_capacity);
...@@ -707,7 +707,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -707,7 +707,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
707 self: *Self,707 self: *Self,
708 allocator: Allocator,708 allocator: Allocator,
709 additional_count: usize,709 additional_count: usize,
710 ) !void {710 ) Allocator.Error!void {
711 return self.ensureTotalCapacity(allocator, self.items.len + additional_count);711 return self.ensureTotalCapacity(allocator, self.items.len + additional_count);
712 }712 }
713713
...@@ -720,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -720,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
720720
721 /// Increase length by 1, returning pointer to the new item.721 /// Increase length by 1, returning pointer to the new item.
722 /// The returned pointer becomes invalid when the list resized.722 /// The returned pointer becomes invalid when the list resized.
723 pub fn addOne(self: *Self, allocator: Allocator) !*T {723 pub fn addOne(self: *Self, allocator: Allocator) Allocator.Error!*T {
724 const newlen = self.items.len + 1;724 const newlen = self.items.len + 1;
725 try self.ensureTotalCapacity(allocator, newlen);725 try self.ensureTotalCapacity(allocator, newlen);
726 return self.addOneAssumeCapacity();726 return self.addOneAssumeCapacity();
...@@ -740,7 +740,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -740,7 +740,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
740 /// Resize the array, adding `n` new elements, which have `undefined` values.740 /// Resize the array, adding `n` new elements, which have `undefined` values.
741 /// The return value is an array pointing to the newly allocated elements.741 /// The return value is an array pointing to the newly allocated elements.
742 /// The returned pointer becomes invalid when the list is resized.742 /// The returned pointer becomes invalid when the list is resized.
743 pub fn addManyAsArray(self: *Self, allocator: Allocator, comptime n: usize) !*[n]T {743 pub fn addManyAsArray(self: *Self, allocator: Allocator, comptime n: usize) Allocator.Error!*[n]T {
744 const prev_len = self.items.len;744 const prev_len = self.items.len;
745 try self.resize(allocator, self.items.len + n);745 try self.resize(allocator, self.items.len + n);
746 return self.items[prev_len..][0..n];746 return self.items[prev_len..][0..n];