authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-19 15:46:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-19 16:24:51-07:00
log827e30634fcb907c584bcf68505354771068c22a
tree0178d620de9d15ab0b7fc039d00dfba9c9e3434a
parent4ddd0b1a1bbcb18fa34dc5c1ab2d4f427df376b3

std.ArrayList: pedantic fixups to previous commit

* fix and clarify incorrect doc comments * unify the pattern of calling unmanaged methods

1 files changed, 13 insertions(+), 19 deletions(-)

lib/std/array_list.zig+13-19
......@@ -238,10 +238,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
238238 @memcpy(dst, items);
239239 }
240240
241 /// Replace range of elements `list[start..][0..len]` with `new_items`.
242 /// Grows list if `len < new_items.len`.
243 /// Shrinks list if `len > new_items.len`.
244 /// Invalidates element pointers if this ArrayList is resized.
241 /// Grows or shrinks the list as necessary.
242 /// Invalidates element pointers if additional capacity is allocated.
245243 /// Asserts that the range is in bounds.
246244 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
247245 var unmanaged = self.moveToUnmanaged();
......@@ -249,14 +247,13 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
249247 return unmanaged.replaceRange(self.allocator, start, len, new_items);
250248 }
251249
252 /// Replace range of elements `list[start..][0..len]` with `new_items`.
253 /// If `len < new_items.len` then it asserts that `.capacity` is
254 /// large enough for the increase in items.
255 /// Invalidates pointers if this ArrayList is resized.
250 /// Grows or shrinks the list as necessary.
251 /// Never invalidates element pointers.
252 /// Asserts the capacity is enough for additional items.
256253 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
257254 var unmanaged = self.moveToUnmanaged();
258 unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
259 self.* = unmanaged.toManaged(self.allocator);
255 defer self.* = unmanaged.toManaged(self.allocator);
256 return unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
260257 }
261258
262259 /// 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
795792 @memcpy(dst, items);
796793 }
797794
798 /// Replace range of elements `list[start..][0..len]` with `new_items`
799 /// Grows list if `len < new_items.len`.
800 /// Shrinks list if `len > new_items.len`
801 /// Invalidates element pointers if this ArrayList is resized.
802 /// Asserts that the start index is in bounds or equal to the length.
795 /// Grows or shrinks the list as necessary.
796 /// Invalidates element pointers if additional capacity is allocated.
797 /// Asserts that the range is in bounds.
803798 pub fn replaceRange(
804799 self: *Self,
805800 allocator: Allocator,
......@@ -819,10 +814,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
819814 }
820815 }
821816
822 /// Replace range of elements `list[start..][0..len]` with `new_items`.
823 /// Grows list if `len < new_items.len`.
824 /// Shrinks list if `len > new_items.len`.
825 /// Invalidates pointers if this ArrayList is resized.
817 /// Grows or shrinks the list as necessary.
818 /// Never invalidates element pointers.
819 /// Asserts the capacity is enough for additional items.
826820 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
827821 const after_range = start + len;
828822 const range = self.items[start..after_range];