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 {...@@ -238,10 +238,8 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
238 @memcpy(dst, items);238 @memcpy(dst, items);
239 }239 }
240240
241 /// Replace range of elements `list[start..][0..len]` with `new_items`.241 /// Grows or shrinks the list as necessary.
242 /// Grows list if `len < new_items.len`.242 /// Invalidates element pointers if additional capacity is allocated.
243 /// Shrinks list if `len > new_items.len`.
244 /// Invalidates element pointers if this ArrayList is resized.
245 /// Asserts that the range is in bounds.243 /// Asserts that the range is in bounds.
246 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {244 pub fn replaceRange(self: *Self, start: usize, len: usize, new_items: []const T) Allocator.Error!void {
247 var unmanaged = self.moveToUnmanaged();245 var unmanaged = self.moveToUnmanaged();
...@@ -249,14 +247,13 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -249,14 +247,13 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
249 return unmanaged.replaceRange(self.allocator, start, len, new_items);247 return unmanaged.replaceRange(self.allocator, start, len, new_items);
250 }248 }
251249
252 /// Replace range of elements `list[start..][0..len]` with `new_items`.250 /// Grows or shrinks the list as necessary.
253 /// If `len < new_items.len` then it asserts that `.capacity` is251 /// Never invalidates element pointers.
254 /// large enough for the increase in items.252 /// Asserts the capacity is enough for additional items.
255 /// Invalidates pointers if this ArrayList is resized.
256 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {253 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
257 var unmanaged = self.moveToUnmanaged();254 var unmanaged = self.moveToUnmanaged();
258 unmanaged.replaceRangeAssumeCapacity(start, len, new_items);255 defer self.* = unmanaged.toManaged(self.allocator);
259 self.* = unmanaged.toManaged(self.allocator);256 return unmanaged.replaceRangeAssumeCapacity(start, len, new_items);
260 }257 }
261258
262 /// Extends the list by 1 element. Allocates more memory as necessary.259 /// 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...@@ -795,11 +792,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
795 @memcpy(dst, items);792 @memcpy(dst, items);
796 }793 }
797794
798 /// Replace range of elements `list[start..][0..len]` with `new_items`795 /// Grows or shrinks the list as necessary.
799 /// Grows list if `len < new_items.len`.796 /// Invalidates element pointers if additional capacity is allocated.
800 /// Shrinks list if `len > new_items.len`797 /// Asserts that the range is in bounds.
801 /// Invalidates element pointers if this ArrayList is resized.
802 /// Asserts that the start index is in bounds or equal to the length.
803 pub fn replaceRange(798 pub fn replaceRange(
804 self: *Self,799 self: *Self,
805 allocator: Allocator,800 allocator: Allocator,
...@@ -819,10 +814,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -819,10 +814,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
819 }814 }
820 }815 }
821816
822 /// Replace range of elements `list[start..][0..len]` with `new_items`.817 /// Grows or shrinks the list as necessary.
823 /// Grows list if `len < new_items.len`.818 /// Never invalidates element pointers.
824 /// Shrinks list if `len > new_items.len`.819 /// Asserts the capacity is enough for additional items.
825 /// Invalidates pointers if this ArrayList is resized.
826 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {820 pub fn replaceRangeAssumeCapacity(self: *Self, start: usize, len: usize, new_items: []const T) void {
827 const after_range = start + len;821 const after_range = start + len;
828 const range = self.items[start..after_range];822 const range = self.items[start..after_range];