| ... | ... | @@ -306,18 +306,22 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 306 | 306 | /// Append a value to the list `n` times. |
| 307 | 307 | /// Allocates more memory as necessary. |
| 308 | 308 | /// Invalidates pointers if additional memory is needed. |
| 309 | | pub fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void { |
| 309 | /// The function is inline so that a comptime-known `value` parameter will |
| 310 | /// have a more optimal memset codegen in case it has a repeated byte pattern. |
| 311 | pub inline fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void { |
| 310 | 312 | const old_len = self.items.len; |
| 311 | 313 | try self.resize(self.items.len + n); |
| 312 | | mem.set(T, self.items[old_len..self.items.len], value); |
| 314 | @memset(self.items[old_len..self.items.len], value); |
| 313 | 315 | } |
| 314 | 316 | |
| 315 | 317 | /// Append a value to the list `n` times. |
| 316 | 318 | /// Asserts the capacity is enough. **Does not** invalidate pointers. |
| 317 | | pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { |
| 319 | /// The function is inline so that a comptime-known `value` parameter will |
| 320 | /// have a more optimal memset codegen in case it has a repeated byte pattern. |
| 321 | pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { |
| 318 | 322 | const new_len = self.items.len + n; |
| 319 | 323 | assert(new_len <= self.capacity); |
| 320 | | mem.set(T, self.items.ptr[self.items.len..new_len], value); |
| 324 | @memset(self.items.ptr[self.items.len..new_len], value); |
| 321 | 325 | self.items.len = new_len; |
| 322 | 326 | } |
| 323 | 327 | |
| ... | ... | @@ -766,19 +770,23 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 766 | 770 | /// Append a value to the list `n` times. |
| 767 | 771 | /// Allocates more memory as necessary. |
| 768 | 772 | /// Invalidates pointers if additional memory is needed. |
| 769 | | pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void { |
| 773 | /// The function is inline so that a comptime-known `value` parameter will |
| 774 | /// have a more optimal memset codegen in case it has a repeated byte pattern. |
| 775 | pub inline fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void { |
| 770 | 776 | const old_len = self.items.len; |
| 771 | 777 | try self.resize(allocator, self.items.len + n); |
| 772 | | mem.set(T, self.items[old_len..self.items.len], value); |
| 778 | @memset(self.items[old_len..self.items.len], value); |
| 773 | 779 | } |
| 774 | 780 | |
| 775 | 781 | /// Append a value to the list `n` times. |
| 776 | 782 | /// **Does not** invalidate pointers. |
| 777 | 783 | /// Asserts the capacity is enough. |
| 778 | | pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { |
| 784 | /// The function is inline so that a comptime-known `value` parameter will |
| 785 | /// have a more optimal memset codegen in case it has a repeated byte pattern. |
| 786 | pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { |
| 779 | 787 | const new_len = self.items.len + n; |
| 780 | 788 | assert(new_len <= self.capacity); |
| 781 | | mem.set(T, self.items.ptr[self.items.len..new_len], value); |
| 789 | @memset(self.items.ptr[self.items.len..new_len], value); |
| 782 | 790 | self.items.len = new_len; |
| 783 | 791 | } |
| 784 | 792 | |