aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorErik Arvstedt <erik.arvstedt@gmail.com>2024-01-19 00:25:44 +0100
committerErik Arvstedt <erik.arvstedt@gmail.com>2024-01-19 00:55:17 +0100
commitc50ba2d1019b025d278e0644903b1358a70415b5 (patch)
treedf046fc02554b5b2ad38a2f56bac30cf04e888d2 /lib/std/array_list.zig
parent0bb6967d1464d95e50ef620ea5b3ebd9f9c0bc97 (diff)
downloadzig-c50ba2d1019b025d278e0644903b1358a70415b5.tar.gz
zig-c50ba2d1019b025d278e0644903b1358a70415b5.zip
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`.
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 18b741f1c3..24d905454a 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -242,9 +242,9 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Grows list if `len < new_items.len`.
/// Shrinks list if `len > new_items.len`.
/// Invalidates element pointers if this ArrayList is resized.
- /// Asserts that the start index is in bounds or equal to the length.
+ /// Asserts that the range is in bounds.
pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
- const after_range = try addOrOom(start, len);
+ const after_range = start + len;
const range = self.items[start..after_range];
if (range.len == new_items.len)
@@ -257,7 +257,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
try self.insertSlice(after_range, rest);
} else {
@memcpy(range[0..new_items.len], new_items);
- const after_subrange = try addOrOom(start, new_items.len);
+ const after_subrange = start + new_items.len;
for (self.items[after_range..], 0..) |item, i| {
self.items[after_subrange..][i] = item;