| ... | @@ -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 | } |
| 240 | | 240 | |
| 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 | } |
| 251 | | 249 | |
| 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` is | 251 | /// 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 | } |
| 261 | | 258 | |
| 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 | } |
| 797 | | 794 | |
| 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 | } |
| 821 | | 816 | |
| 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]; |