authorgravatar for erik.arvstedt@gmail.comErik Arvstedt <erik.arvstedt@gmail.com> 2024-01-19 00:25:44+01:00
committergravatar for erik.arvstedt@gmail.comErik Arvstedt <erik.arvstedt@gmail.com> 2024-01-19 00:55:17+01:00
logc50ba2d1019b025d278e0644903b1358a70415b5
treedf046fc02554b5b2ad38a2f56bac30cf04e888d2
parent0bb6967d1464d95e50ef620ea5b3ebd9f9c0bc97

std.ArrayList.replaceRange: remove unneded overflow checks

The code asserted that the range to be replaced is within bounds of `self.items`. This is now reflected in the doc comment. The old, wrong doc comment was copied from the `insert*` fns. With this assertion holding true, `start + len` is always within the address space and `start + new_items.len` is, at this point, always strictly within bounds of `self.items`.

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

lib/std/array_list.zig+3-3
......@@ -242,9 +242,9 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
242242 /// Grows list if `len < new_items.len`.
243243 /// Shrinks list if `len > new_items.len`.
244244 /// Invalidates element pointers if this ArrayList is resized.
245 /// Asserts that the start index is in bounds or equal to the length.
245 /// Asserts that the range is in bounds.
246246 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
247 const after_range = try addOrOom(start, len);
247 const after_range = start + len;
248248 const range = self.items[start..after_range];
249249
250250 if (range.len == new_items.len)
......@@ -257,7 +257,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
257257 try self.insertSlice(after_range, rest);
258258 } else {
259259 @memcpy(range[0..new_items.len], new_items);
260 const after_subrange = try addOrOom(start, new_items.len);
260 const after_subrange = start + new_items.len;
261261
262262 for (self.items[after_range..], 0..) |item, i| {
263263 self.items[after_subrange..][i] = item;