diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-21 03:18:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-21 03:18:39 -0400 |
| commit | 26984852bdfdbe3564b19f3ff7b3ecfd606c9902 (patch) | |
| tree | a64c806e3e9900c4eb0cd281a9d6946ce07421f5 /lib/std/array_list.zig | |
| parent | bfe20051673e285d3b1788cd637fab9ca84d1cb1 (diff) | |
| parent | c39c46c0d12b15874b1586ff47cf473b31867918 (diff) | |
| download | zig-26984852bdfdbe3564b19f3ff7b3ecfd606c9902.tar.gz zig-26984852bdfdbe3564b19f3ff7b3ecfd606c9902.zip | |
Merge pull request #9353 from ziglang/stage2-air
stage2: rework AIR memory layout
Diffstat (limited to 'lib/std/array_list.zig')
| -rw-r--r-- | lib/std/array_list.zig | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index f55ef81a6b..8b46ec2145 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -227,10 +227,11 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { /// Append the slice of items to the list, asserting the capacity is already /// enough to store the new items. **Does not** invalidate pointers. pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void { - const oldlen = self.items.len; - const newlen = self.items.len + items.len; - self.items.len = newlen; - mem.copy(T, self.items[oldlen..], items); + const old_len = self.items.len; + const new_len = old_len + items.len; + assert(new_len <= self.capacity); + self.items.len = new_len; + mem.copy(T, self.items[old_len..], items); } pub usingnamespace if (T != u8) struct {} else struct { @@ -570,11 +571,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ /// Append the slice of items to the list, asserting the capacity is enough /// to store the new items. pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void { - const oldlen = self.items.len; - const newlen = self.items.len + items.len; - - self.items.len = newlen; - mem.copy(T, self.items[oldlen..], items); + const old_len = self.items.len; + const new_len = old_len + items.len; + assert(new_len <= self.capacity); + self.items.len = new_len; + mem.copy(T, self.items[old_len..], items); } /// Append a value to the list `n` times. |
