aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-01-19 15:46:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-01-19 16:24:51 -0700
commit827e30634fcb907c584bcf68505354771068c22a (patch)
tree0178d620de9d15ab0b7fc039d00dfba9c9e3434a /lib/std/array_list.zig
parent4ddd0b1a1bbcb18fa34dc5c1ab2d4f427df376b3 (diff)
downloadzig-827e30634fcb907c584bcf68505354771068c22a.tar.gz
zig-827e30634fcb907c584bcf68505354771068c22a.zip
std.ArrayList: pedantic fixups to previous commit
* fix and clarify incorrect doc comments * unify the pattern of calling unmanaged methods
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig32
1 files changed, 13 insertions, 19 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 55a3448403..79ed5c192c 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -238,10 +238,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
@memcpy(dst, items);
}
- /// Replace range of elements `list[start..][0..len]` with `new_items`.
- /// Grows list if `len < new_items.len`.
- /// Shrinks list if `len > new_items.len`.
- /// Invalidates element pointers if this ArrayList is resized.
+ /// Grows or shrinks the list as necessary.
+ /// Invalidates element pointers if additional capacity is allocated.
/// Asserts that the range is in bounds.
pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
var unmanaged = self.moveToUnmanaged();
@@ -249,14 +247,13 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
return unmanaged.replaceRange(self.allocator, start, len, new_items);
}
- /// Replace range of elements `list[start..][0..len]` with `new_items`.
- /// If `len < new_items.len` then it asserts that `.capacity` is
- /// large enough for the increase in items.
- /// Invalidates pointers if this ArrayList is resized.
+ /// Grows or shrinks the list as necessary.
+ /// Never invalidates element pointers.
+ /// Asserts the capacity is enough for additional items.
pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
var unmanaged = self.moveToUnmanaged();
- unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
- self.* = unmanaged.toManaged(self.allocator);
+ defer self.* = unmanaged.toManaged(self.allocator);
+ return unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
}
/// Extends the list by 1 element. Allocates more memory as necessary.
@@ -795,11 +792,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
@memcpy(dst, items);
}
- /// Replace range of elements `list[start..][0..len]` with `new_items`
- /// 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.
+ /// Grows or shrinks the list as necessary.
+ /// Invalidates element pointers if additional capacity is allocated.
+ /// Asserts that the range is in bounds.
pub fn replaceRange(
self: *Self,
allocator: Allocator,
@@ -819,10 +814,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
}
}
- /// Replace range of elements `list[start..][0..len]` with `new_items`.
- /// Grows list if `len < new_items.len`.
- /// Shrinks list if `len > new_items.len`.
- /// Invalidates pointers if this ArrayList is resized.
+ /// Grows or shrinks the list as necessary.
+ /// Never invalidates element pointers.
+ /// Asserts the capacity is enough for additional items.
pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
const after_range = start + len;
const range = self.items[start..after_range];