| author | |
| committer | |
| log | 59f5053beda7087a73983835e9f7e00dc3143d59 |
| tree | d43b3a97472532c699d8ee9d741ae97766d3e209 |
| parent | feeb25908bebd5d09cf05128fad7d7c1a8a803a1 |
38 files changed, 134 insertions(+), 137 deletions(-)
lib/std/array_hash_map.zig+10-10| ... | @@ -90,7 +90,7 @@ pub fn ArrayHashMap( | ... | @@ -90,7 +90,7 @@ pub fn ArrayHashMap( |
| 90 | /// Modifying the key is allowed only if it does not change the hash. | 90 | /// Modifying the key is allowed only if it does not change the hash. |
| 91 | /// Modifying the value is allowed. | 91 | /// Modifying the value is allowed. |
| 92 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, | 92 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, |
| 93 | /// unless `ensureCapacity` was previously used. | 93 | /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used. |
| 94 | pub const Entry = Unmanaged.Entry; | 94 | pub const Entry = Unmanaged.Entry; |
| 95 | 95 | ||
| 96 | /// A KV pair which has been copied out of the backing store | 96 | /// A KV pair which has been copied out of the backing store |
| ... | @@ -110,7 +110,7 @@ pub fn ArrayHashMap( | ... | @@ -110,7 +110,7 @@ pub fn ArrayHashMap( |
| 110 | /// Modifying the key is allowed only if it does not change the hash. | 110 | /// Modifying the key is allowed only if it does not change the hash. |
| 111 | /// Modifying the value is allowed. | 111 | /// Modifying the value is allowed. |
| 112 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, | 112 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, |
| 113 | /// unless `ensureCapacity` was previously used. | 113 | /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used. |
| 114 | pub const GetOrPutResult = Unmanaged.GetOrPutResult; | 114 | pub const GetOrPutResult = Unmanaged.GetOrPutResult; |
| 115 | 115 | ||
| 116 | /// An Iterator over Entry pointers. | 116 | /// An Iterator over Entry pointers. |
| ... | @@ -478,7 +478,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -478,7 +478,7 @@ pub fn ArrayHashMapUnmanaged( |
| 478 | /// Modifying the key is allowed only if it does not change the hash. | 478 | /// Modifying the key is allowed only if it does not change the hash. |
| 479 | /// Modifying the value is allowed. | 479 | /// Modifying the value is allowed. |
| 480 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, | 480 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, |
| 481 | /// unless `ensureCapacity` was previously used. | 481 | /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used. |
| 482 | pub const Entry = struct { | 482 | pub const Entry = struct { |
| 483 | key_ptr: *K, | 483 | key_ptr: *K, |
| 484 | value_ptr: *V, | 484 | value_ptr: *V, |
| ... | @@ -509,7 +509,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -509,7 +509,7 @@ pub fn ArrayHashMapUnmanaged( |
| 509 | /// Modifying the key is allowed only if it does not change the hash. | 509 | /// Modifying the key is allowed only if it does not change the hash. |
| 510 | /// Modifying the value is allowed. | 510 | /// Modifying the value is allowed. |
| 511 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, | 511 | /// Entry pointers become invalid whenever this ArrayHashMap is modified, |
| 512 | /// unless `ensureCapacity` was previously used. | 512 | /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used. |
| 513 | pub const GetOrPutResult = struct { | 513 | pub const GetOrPutResult = struct { |
| 514 | key_ptr: *K, | 514 | key_ptr: *K, |
| 515 | value_ptr: *V, | 515 | value_ptr: *V, |
| ... | @@ -759,20 +759,20 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -759,20 +759,20 @@ pub fn ArrayHashMapUnmanaged( |
| 759 | } | 759 | } |
| 760 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void { | 760 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void { |
| 761 | if (new_capacity <= linear_scan_max) { | 761 | if (new_capacity <= linear_scan_max) { |
| 762 | try self.entries.ensureCapacity(allocator, new_capacity); | 762 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 763 | return; | 763 | return; |
| 764 | } | 764 | } |
| 765 | 765 | ||
| 766 | if (self.index_header) |header| { | 766 | if (self.index_header) |header| { |
| 767 | if (new_capacity <= header.capacity()) { | 767 | if (new_capacity <= header.capacity()) { |
| 768 | try self.entries.ensureCapacity(allocator, new_capacity); | 768 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 769 | return; | 769 | return; |
| 770 | } | 770 | } |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | const new_bit_index = try IndexHeader.findBitIndex(new_capacity); | 773 | const new_bit_index = try IndexHeader.findBitIndex(new_capacity); |
| 774 | const new_header = try IndexHeader.alloc(allocator, new_bit_index); | 774 | const new_header = try IndexHeader.alloc(allocator, new_bit_index); |
| 775 | try self.entries.ensureCapacity(allocator, new_capacity); | 775 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 776 | 776 | ||
| 777 | if (self.index_header) |old_header| old_header.free(allocator); | 777 | if (self.index_header) |old_header| old_header.free(allocator); |
| 778 | self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header); | 778 | self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header); |
| ... | @@ -1441,7 +1441,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1441,7 +1441,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1441 | unreachable; | 1441 | unreachable; |
| 1442 | } | 1442 | } |
| 1443 | 1443 | ||
| 1444 | /// Must ensureCapacity before calling this. | 1444 | /// Must `ensureTotalCapacity`/`ensureUnusedCapacity` before calling this. |
| 1445 | fn getOrPutInternal(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type) GetOrPutResult { | 1445 | fn getOrPutInternal(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type) GetOrPutResult { |
| 1446 | const slice = self.entries.slice(); | 1446 | const slice = self.entries.slice(); |
| 1447 | const hashes_array = if (store_hash) slice.items(.hash) else {}; | 1447 | const hashes_array = if (store_hash) slice.items(.hash) else {}; |
| ... | @@ -1485,7 +1485,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1485,7 +1485,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1485 | } | 1485 | } |
| 1486 | 1486 | ||
| 1487 | // This pointer survives the following append because we call | 1487 | // This pointer survives the following append because we call |
| 1488 | // entries.ensureCapacity before getOrPutInternal. | 1488 | // entries.ensureTotalCapacity before getOrPutInternal. |
| 1489 | const hash_match = if (store_hash) h == hashes_array[slot_data.entry_index] else true; | 1489 | const hash_match = if (store_hash) h == hashes_array[slot_data.entry_index] else true; |
| 1490 | if (hash_match and checkedEql(ctx, key, keys_array[slot_data.entry_index])) { | 1490 | if (hash_match and checkedEql(ctx, key, keys_array[slot_data.entry_index])) { |
| 1491 | return .{ | 1491 | return .{ |
| ... | @@ -1946,7 +1946,7 @@ test "iterator hash map" { | ... | @@ -1946,7 +1946,7 @@ test "iterator hash map" { |
| 1946 | var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); | 1946 | var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); |
| 1947 | defer reset_map.deinit(); | 1947 | defer reset_map.deinit(); |
| 1948 | 1948 | ||
| 1949 | // test ensureCapacity with a 0 parameter | 1949 | // test ensureTotalCapacity with a 0 parameter |
| 1950 | try reset_map.ensureTotalCapacity(0); | 1950 | try reset_map.ensureTotalCapacity(0); |
| 1951 | 1951 | ||
| 1952 | try reset_map.putNoClobber(0, 11); | 1952 | try reset_map.putNoClobber(0, 11); |
lib/std/child_process.zig+5-5| ... | @@ -195,7 +195,7 @@ pub const ChildProcess = struct { | ... | @@ -195,7 +195,7 @@ pub const ChildProcess = struct { |
| 195 | }; | 195 | }; |
| 196 | 196 | ||
| 197 | var dead_fds: usize = 0; | 197 | var dead_fds: usize = 0; |
| 198 | // We ask for ensureCapacity with this much extra space. This has more of an | 198 | // We ask for ensureTotalCapacity with this much extra space. This has more of an |
| 199 | // effect on small reads because once the reads start to get larger the amount | 199 | // effect on small reads because once the reads start to get larger the amount |
| 200 | // of space an ArrayList will allocate grows exponentially. | 200 | // of space an ArrayList will allocate grows exponentially. |
| 201 | const bump_amt = 512; | 201 | const bump_amt = 512; |
| ... | @@ -215,7 +215,7 @@ pub const ChildProcess = struct { | ... | @@ -215,7 +215,7 @@ pub const ChildProcess = struct { |
| 215 | if (poll_fds[0].revents & os.POLL.IN != 0) { | 215 | if (poll_fds[0].revents & os.POLL.IN != 0) { |
| 216 | // stdout is ready. | 216 | // stdout is ready. |
| 217 | const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes); | 217 | const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes); |
| 218 | try stdout.ensureCapacity(new_capacity); | 218 | try stdout.ensureTotalCapacity(new_capacity); |
| 219 | const buf = stdout.unusedCapacitySlice(); | 219 | const buf = stdout.unusedCapacitySlice(); |
| 220 | if (buf.len == 0) return error.StdoutStreamTooLong; | 220 | if (buf.len == 0) return error.StdoutStreamTooLong; |
| 221 | const nread = try os.read(poll_fds[0].fd, buf); | 221 | const nread = try os.read(poll_fds[0].fd, buf); |
| ... | @@ -230,7 +230,7 @@ pub const ChildProcess = struct { | ... | @@ -230,7 +230,7 @@ pub const ChildProcess = struct { |
| 230 | if (poll_fds[1].revents & os.POLL.IN != 0) { | 230 | if (poll_fds[1].revents & os.POLL.IN != 0) { |
| 231 | // stderr is ready. | 231 | // stderr is ready. |
| 232 | const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes); | 232 | const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes); |
| 233 | try stderr.ensureCapacity(new_capacity); | 233 | try stderr.ensureTotalCapacity(new_capacity); |
| 234 | const buf = stderr.unusedCapacitySlice(); | 234 | const buf = stderr.unusedCapacitySlice(); |
| 235 | if (buf.len == 0) return error.StderrStreamTooLong; | 235 | if (buf.len == 0) return error.StderrStreamTooLong; |
| 236 | const nread = try os.read(poll_fds[1].fd, buf); | 236 | const nread = try os.read(poll_fds[1].fd, buf); |
| ... | @@ -276,7 +276,7 @@ pub const ChildProcess = struct { | ... | @@ -276,7 +276,7 @@ pub const ChildProcess = struct { |
| 276 | 276 | ||
| 277 | // Windows Async IO requires an initial call to ReadFile before waiting on the handle | 277 | // Windows Async IO requires an initial call to ReadFile before waiting on the handle |
| 278 | for ([_]u1{ 0, 1 }) |i| { | 278 | for ([_]u1{ 0, 1 }) |i| { |
| 279 | try outs[i].ensureCapacity(bump_amt); | 279 | try outs[i].ensureTotalCapacity(bump_amt); |
| 280 | const buf = outs[i].unusedCapacitySlice(); | 280 | const buf = outs[i].unusedCapacitySlice(); |
| 281 | _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]); | 281 | _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]); |
| 282 | wait_objects[wait_object_count] = handles[i]; | 282 | wait_objects[wait_object_count] = handles[i]; |
| ... | @@ -318,7 +318,7 @@ pub const ChildProcess = struct { | ... | @@ -318,7 +318,7 @@ pub const ChildProcess = struct { |
| 318 | 318 | ||
| 319 | outs[i].items.len += read_bytes; | 319 | outs[i].items.len += read_bytes; |
| 320 | const new_capacity = std.math.min(outs[i].items.len + bump_amt, max_output_bytes); | 320 | const new_capacity = std.math.min(outs[i].items.len + bump_amt, max_output_bytes); |
| 321 | try outs[i].ensureCapacity(new_capacity); | 321 | try outs[i].ensureTotalCapacity(new_capacity); |
| 322 | const buf = outs[i].unusedCapacitySlice(); | 322 | const buf = outs[i].unusedCapacitySlice(); |
| 323 | if (buf.len == 0) return if (i == 0) error.StdoutStreamTooLong else error.StderrStreamTooLong; | 323 | if (buf.len == 0) return if (i == 0) error.StdoutStreamTooLong else error.StderrStreamTooLong; |
| 324 | _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]); | 324 | _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]); |
lib/std/coff.zig+1-1| ... | @@ -277,7 +277,7 @@ pub const Coff = struct { | ... | @@ -277,7 +277,7 @@ pub const Coff = struct { |
| 277 | if (self.sections.items.len == self.coff_header.number_of_sections) | 277 | if (self.sections.items.len == self.coff_header.number_of_sections) |
| 278 | return; | 278 | return; |
| 279 | 279 | ||
| 280 | try self.sections.ensureCapacity(self.coff_header.number_of_sections); | 280 | try self.sections.ensureTotalCapacity(self.coff_header.number_of_sections); |
| 281 | 281 | ||
| 282 | const in = self.in_file.reader(); | 282 | const in = self.in_file.reader(); |
| 283 | 283 |
lib/std/hash_map.zig+9-9| ... | @@ -1568,11 +1568,11 @@ test "std.hash_map basic usage" { | ... | @@ -1568,11 +1568,11 @@ test "std.hash_map basic usage" { |
| 1568 | try expectEqual(total, sum); | 1568 | try expectEqual(total, sum); |
| 1569 | } | 1569 | } |
| 1570 | 1570 | ||
| 1571 | test "std.hash_map ensureCapacity" { | 1571 | test "std.hash_map ensureTotalCapacity" { |
| 1572 | var map = AutoHashMap(i32, i32).init(std.testing.allocator); | 1572 | var map = AutoHashMap(i32, i32).init(std.testing.allocator); |
| 1573 | defer map.deinit(); | 1573 | defer map.deinit(); |
| 1574 | 1574 | ||
| 1575 | try map.ensureCapacity(20); | 1575 | try map.ensureTotalCapacity(20); |
| 1576 | const initial_capacity = map.capacity(); | 1576 | const initial_capacity = map.capacity(); |
| 1577 | try testing.expect(initial_capacity >= 20); | 1577 | try testing.expect(initial_capacity >= 20); |
| 1578 | var i: i32 = 0; | 1578 | var i: i32 = 0; |
| ... | @@ -1583,13 +1583,13 @@ test "std.hash_map ensureCapacity" { | ... | @@ -1583,13 +1583,13 @@ test "std.hash_map ensureCapacity" { |
| 1583 | try testing.expect(initial_capacity == map.capacity()); | 1583 | try testing.expect(initial_capacity == map.capacity()); |
| 1584 | } | 1584 | } |
| 1585 | 1585 | ||
| 1586 | test "std.hash_map ensureCapacity with tombstones" { | 1586 | test "std.hash_map ensureUnusedCapacity with tombstones" { |
| 1587 | var map = AutoHashMap(i32, i32).init(std.testing.allocator); | 1587 | var map = AutoHashMap(i32, i32).init(std.testing.allocator); |
| 1588 | defer map.deinit(); | 1588 | defer map.deinit(); |
| 1589 | 1589 | ||
| 1590 | var i: i32 = 0; | 1590 | var i: i32 = 0; |
| 1591 | while (i < 100) : (i += 1) { | 1591 | while (i < 100) : (i += 1) { |
| 1592 | try map.ensureCapacity(@intCast(u32, map.count() + 1)); | 1592 | try map.ensureUnusedCapacity(1); |
| 1593 | map.putAssumeCapacity(i, i); | 1593 | map.putAssumeCapacity(i, i); |
| 1594 | // Remove to create tombstones that still count as load in the hashmap. | 1594 | // Remove to create tombstones that still count as load in the hashmap. |
| 1595 | _ = map.remove(i); | 1595 | _ = map.remove(i); |
| ... | @@ -1669,7 +1669,7 @@ test "std.hash_map clone" { | ... | @@ -1669,7 +1669,7 @@ test "std.hash_map clone" { |
| 1669 | try expectEqual(b.get(3).?, 3); | 1669 | try expectEqual(b.get(3).?, 3); |
| 1670 | } | 1670 | } |
| 1671 | 1671 | ||
| 1672 | test "std.hash_map ensureCapacity with existing elements" { | 1672 | test "std.hash_map ensureTotalCapacity with existing elements" { |
| 1673 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); | 1673 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); |
| 1674 | defer map.deinit(); | 1674 | defer map.deinit(); |
| 1675 | 1675 | ||
| ... | @@ -1677,16 +1677,16 @@ test "std.hash_map ensureCapacity with existing elements" { | ... | @@ -1677,16 +1677,16 @@ test "std.hash_map ensureCapacity with existing elements" { |
| 1677 | try expectEqual(map.count(), 1); | 1677 | try expectEqual(map.count(), 1); |
| 1678 | try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity); | 1678 | try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity); |
| 1679 | 1679 | ||
| 1680 | try map.ensureCapacity(65); | 1680 | try map.ensureTotalCapacity(65); |
| 1681 | try expectEqual(map.count(), 1); | 1681 | try expectEqual(map.count(), 1); |
| 1682 | try expectEqual(map.capacity(), 128); | 1682 | try expectEqual(map.capacity(), 128); |
| 1683 | } | 1683 | } |
| 1684 | 1684 | ||
| 1685 | test "std.hash_map ensureCapacity satisfies max load factor" { | 1685 | test "std.hash_map ensureTotalCapacity satisfies max load factor" { |
| 1686 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); | 1686 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); |
| 1687 | defer map.deinit(); | 1687 | defer map.deinit(); |
| 1688 | 1688 | ||
| 1689 | try map.ensureCapacity(127); | 1689 | try map.ensureTotalCapacity(127); |
| 1690 | try expectEqual(map.capacity(), 256); | 1690 | try expectEqual(map.capacity(), 256); |
| 1691 | } | 1691 | } |
| 1692 | 1692 | ||
| ... | @@ -1870,7 +1870,7 @@ test "std.hash_map putAssumeCapacity" { | ... | @@ -1870,7 +1870,7 @@ test "std.hash_map putAssumeCapacity" { |
| 1870 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); | 1870 | var map = AutoHashMap(u32, u32).init(std.testing.allocator); |
| 1871 | defer map.deinit(); | 1871 | defer map.deinit(); |
| 1872 | 1872 | ||
| 1873 | try map.ensureCapacity(20); | 1873 | try map.ensureTotalCapacity(20); |
| 1874 | var i: u32 = 0; | 1874 | var i: u32 = 0; |
| 1875 | while (i < 20) : (i += 1) { | 1875 | while (i < 20) : (i += 1) { |
| 1876 | map.putAssumeCapacityNoClobber(i, i); | 1876 | map.putAssumeCapacityNoClobber(i, i); |
lib/std/heap/general_purpose_allocator.zig+1-4| ... | @@ -746,10 +746,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -746,10 +746,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 746 | 746 | ||
| 747 | const new_aligned_size = math.max(len, ptr_align); | 747 | const new_aligned_size = math.max(len, ptr_align); |
| 748 | if (new_aligned_size > largest_bucket_object_size) { | 748 | if (new_aligned_size > largest_bucket_object_size) { |
| 749 | try self.large_allocations.ensureCapacity( | 749 | try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1); |
| 750 | self.backing_allocator, | ||
| 751 | self.large_allocations.count() + 1, | ||
| 752 | ); | ||
| 753 | 750 | ||
| 754 | const slice = try self.backing_allocator.allocFn(self.backing_allocator, len, ptr_align, len_align, ret_addr); | 751 | const slice = try self.backing_allocator.allocFn(self.backing_allocator, len, ptr_align, len_align, ret_addr); |
| 755 | 752 |
lib/std/io/reader.zig+2-2| ... | @@ -61,7 +61,7 @@ pub fn Reader( | ... | @@ -61,7 +61,7 @@ pub fn Reader( |
| 61 | array_list: *std.ArrayListAligned(u8, alignment), | 61 | array_list: *std.ArrayListAligned(u8, alignment), |
| 62 | max_append_size: usize, | 62 | max_append_size: usize, |
| 63 | ) !void { | 63 | ) !void { |
| 64 | try array_list.ensureCapacity(math.min(max_append_size, 4096)); | 64 | try array_list.ensureTotalCapacity(math.min(max_append_size, 4096)); |
| 65 | const original_len = array_list.items.len; | 65 | const original_len = array_list.items.len; |
| 66 | var start_index: usize = original_len; | 66 | var start_index: usize = original_len; |
| 67 | while (true) { | 67 | while (true) { |
| ... | @@ -81,7 +81,7 @@ pub fn Reader( | ... | @@ -81,7 +81,7 @@ pub fn Reader( |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // This will trigger ArrayList to expand superlinearly at whatever its growth rate is. | 83 | // This will trigger ArrayList to expand superlinearly at whatever its growth rate is. |
| 84 | try array_list.ensureCapacity(start_index + 1); | 84 | try array_list.ensureTotalCapacity(start_index + 1); |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 |
lib/std/json.zig+1-1| ... | @@ -1838,7 +1838,7 @@ fn parseInternal( | ... | @@ -1838,7 +1838,7 @@ fn parseInternal( |
| 1838 | else => {}, | 1838 | else => {}, |
| 1839 | } | 1839 | } |
| 1840 | 1840 | ||
| 1841 | try arraylist.ensureCapacity(arraylist.items.len + 1); | 1841 | try arraylist.ensureUnusedCapacity(1); |
| 1842 | const v = try parseInternal(ptrInfo.child, tok, tokens, options); | 1842 | const v = try parseInternal(ptrInfo.child, tok, tokens, options); |
| 1843 | arraylist.appendAssumeCapacity(v); | 1843 | arraylist.appendAssumeCapacity(v); |
| 1844 | } | 1844 | } |
lib/std/multi_array_list.zig+2-2| ... | @@ -189,7 +189,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -189,7 +189,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 189 | /// sets the given index to the specified element. May reallocate | 189 | /// sets the given index to the specified element. May reallocate |
| 190 | /// and invalidate iterators. | 190 | /// and invalidate iterators. |
| 191 | pub fn insert(self: *Self, gpa: *Allocator, index: usize, elem: S) void { | 191 | pub fn insert(self: *Self, gpa: *Allocator, index: usize, elem: S) void { |
| 192 | try self.ensureCapacity(gpa, self.len + 1); | 192 | try self.ensureUnusedCapacity(gpa, 1); |
| 193 | self.insertAssumeCapacity(index, elem); | 193 | self.insertAssumeCapacity(index, elem); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| ... | @@ -376,7 +376,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -376,7 +376,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 376 | pub fn clone(self: Self, gpa: *Allocator) !Self { | 376 | pub fn clone(self: Self, gpa: *Allocator) !Self { |
| 377 | var result = Self{}; | 377 | var result = Self{}; |
| 378 | errdefer result.deinit(gpa); | 378 | errdefer result.deinit(gpa); |
| 379 | try result.ensureCapacity(gpa, self.len); | 379 | try result.ensureTotalCapacity(gpa, self.len); |
| 380 | result.len = self.len; | 380 | result.len = self.len; |
| 381 | const self_slice = self.slice(); | 381 | const self_slice = self.slice(); |
| 382 | const result_slice = result.slice(); | 382 | const result_slice = result.slice(); |
lib/std/unicode.zig+1-1| ... | @@ -668,7 +668,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u | ... | @@ -668,7 +668,7 @@ pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u |
| 668 | var result = std.ArrayList(u16).init(allocator); | 668 | var result = std.ArrayList(u16).init(allocator); |
| 669 | errdefer result.deinit(); | 669 | errdefer result.deinit(); |
| 670 | // optimistically guess that it will not require surrogate pairs | 670 | // optimistically guess that it will not require surrogate pairs |
| 671 | try result.ensureCapacity(utf8.len + 1); | 671 | try result.ensureTotalCapacity(utf8.len + 1); |
| 672 | 672 | ||
| 673 | const view = try Utf8View.init(utf8); | 673 | const view = try Utf8View.init(utf8); |
| 674 | var it = view.iterator(); | 674 | var it = view.iterator(); |
lib/std/zig/parse.zig+3-3| ... | @@ -17,7 +17,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast { | ... | @@ -17,7 +17,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast { |
| 17 | 17 | ||
| 18 | // Empirically, the zig std lib has an 8:1 ratio of source bytes to token count. | 18 | // Empirically, the zig std lib has an 8:1 ratio of source bytes to token count. |
| 19 | const estimated_token_count = source.len / 8; | 19 | const estimated_token_count = source.len / 8; |
| 20 | try tokens.ensureCapacity(gpa, estimated_token_count); | 20 | try tokens.ensureTotalCapacity(gpa, estimated_token_count); |
| 21 | 21 | ||
| 22 | var tokenizer = std.zig.Tokenizer.init(source); | 22 | var tokenizer = std.zig.Tokenizer.init(source); |
| 23 | while (true) { | 23 | while (true) { |
| ... | @@ -48,7 +48,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast { | ... | @@ -48,7 +48,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast { |
| 48 | // Empirically, Zig source code has a 2:1 ratio of tokens to AST nodes. | 48 | // Empirically, Zig source code has a 2:1 ratio of tokens to AST nodes. |
| 49 | // Make sure at least 1 so we can use appendAssumeCapacity on the root node below. | 49 | // Make sure at least 1 so we can use appendAssumeCapacity on the root node below. |
| 50 | const estimated_node_count = (tokens.len + 2) / 2; | 50 | const estimated_node_count = (tokens.len + 2) / 2; |
| 51 | try parser.nodes.ensureCapacity(gpa, estimated_node_count); | 51 | try parser.nodes.ensureTotalCapacity(gpa, estimated_node_count); |
| 52 | 52 | ||
| 53 | // Root node must be index 0. | 53 | // Root node must be index 0. |
| 54 | // Root <- skip ContainerMembers eof | 54 | // Root <- skip ContainerMembers eof |
| ... | @@ -138,7 +138,7 @@ const Parser = struct { | ... | @@ -138,7 +138,7 @@ const Parser = struct { |
| 138 | 138 | ||
| 139 | fn addExtra(p: *Parser, extra: anytype) Allocator.Error!Node.Index { | 139 | fn addExtra(p: *Parser, extra: anytype) Allocator.Error!Node.Index { |
| 140 | const fields = std.meta.fields(@TypeOf(extra)); | 140 | const fields = std.meta.fields(@TypeOf(extra)); |
| 141 | try p.extra_data.ensureCapacity(p.gpa, p.extra_data.items.len + fields.len); | 141 | try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len); |
| 142 | const result = @intCast(u32, p.extra_data.items.len); | 142 | const result = @intCast(u32, p.extra_data.items.len); |
| 143 | inline for (fields) |field| { | 143 | inline for (fields) |field| { |
| 144 | comptime assert(field.field_type == Node.Index); | 144 | comptime assert(field.field_type == Node.Index); |
lib/std/zig/string_literal.zig+1-1| ... | @@ -29,7 +29,7 @@ pub fn parseAppend(buf: *std.ArrayList(u8), bytes: []const u8) error{OutOfMemory | ... | @@ -29,7 +29,7 @@ pub fn parseAppend(buf: *std.ArrayList(u8), bytes: []const u8) error{OutOfMemory |
| 29 | const slice = bytes[1..]; | 29 | const slice = bytes[1..]; |
| 30 | 30 | ||
| 31 | const prev_len = buf.items.len; | 31 | const prev_len = buf.items.len; |
| 32 | try buf.ensureCapacity(prev_len + slice.len - 1); | 32 | try buf.ensureUnusedCapacity(slice.len - 1); |
| 33 | errdefer buf.shrinkRetainingCapacity(prev_len); | 33 | errdefer buf.shrinkRetainingCapacity(prev_len); |
| 34 | 34 | ||
| 35 | const State = enum { | 35 | const State = enum { |
src/AstGen.zig+2-2| ... | @@ -3515,7 +3515,7 @@ fn structDeclInner( | ... | @@ -3515,7 +3515,7 @@ fn structDeclInner( |
| 3515 | defer wip_decls.deinit(gpa); | 3515 | defer wip_decls.deinit(gpa); |
| 3516 | 3516 | ||
| 3517 | // We don't know which members are fields until we iterate, so cannot do | 3517 | // We don't know which members are fields until we iterate, so cannot do |
| 3518 | // an accurate ensureCapacity yet. | 3518 | // an accurate ensureTotalCapacity yet. |
| 3519 | var fields_data = ArrayListUnmanaged(u32){}; | 3519 | var fields_data = ArrayListUnmanaged(u32){}; |
| 3520 | defer fields_data.deinit(gpa); | 3520 | defer fields_data.deinit(gpa); |
| 3521 | 3521 | ||
| ... | @@ -3791,7 +3791,7 @@ fn unionDeclInner( | ... | @@ -3791,7 +3791,7 @@ fn unionDeclInner( |
| 3791 | defer wip_decls.deinit(gpa); | 3791 | defer wip_decls.deinit(gpa); |
| 3792 | 3792 | ||
| 3793 | // We don't know which members are fields until we iterate, so cannot do | 3793 | // We don't know which members are fields until we iterate, so cannot do |
| 3794 | // an accurate ensureCapacity yet. | 3794 | // an accurate ensureTotalCapacity yet. |
| 3795 | var fields_data = ArrayListUnmanaged(u32){}; | 3795 | var fields_data = ArrayListUnmanaged(u32){}; |
| 3796 | defer fields_data.deinit(gpa); | 3796 | defer fields_data.deinit(gpa); |
| 3797 | 3797 |
src/Cache.zig+1-1| ... | @@ -210,7 +210,7 @@ pub const Manifest = struct { | ... | @@ -210,7 +210,7 @@ pub const Manifest = struct { |
| 210 | pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize { | 210 | pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize { |
| 211 | assert(self.manifest_file == null); | 211 | assert(self.manifest_file == null); |
| 212 | 212 | ||
| 213 | try self.files.ensureCapacity(self.cache.gpa, self.files.items.len + 1); | 213 | try self.files.ensureUnusedCapacity(self.cache.gpa, 1); |
| 214 | const resolved_path = try fs.path.resolve(self.cache.gpa, &[_][]const u8{file_path}); | 214 | const resolved_path = try fs.path.resolve(self.cache.gpa, &[_][]const u8{file_path}); |
| 215 | 215 | ||
| 216 | const idx = self.files.items.len; | 216 | const idx = self.files.items.len; |
src/Compilation.zig+9-9| ... | @@ -1097,7 +1097,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1097,7 +1097,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1097 | 1097 | ||
| 1098 | if (feature.llvm_name) |llvm_name| { | 1098 | if (feature.llvm_name) |llvm_name| { |
| 1099 | const plus_or_minus = "-+"[@boolToInt(is_enabled)]; | 1099 | const plus_or_minus = "-+"[@boolToInt(is_enabled)]; |
| 1100 | try buf.ensureCapacity(buf.items.len + 2 + llvm_name.len); | 1100 | try buf.ensureUnusedCapacity(2 + llvm_name.len); |
| 1101 | buf.appendAssumeCapacity(plus_or_minus); | 1101 | buf.appendAssumeCapacity(plus_or_minus); |
| 1102 | buf.appendSliceAssumeCapacity(llvm_name); | 1102 | buf.appendSliceAssumeCapacity(llvm_name); |
| 1103 | buf.appendSliceAssumeCapacity(","); | 1103 | buf.appendSliceAssumeCapacity(","); |
| ... | @@ -1347,7 +1347,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1347,7 +1347,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1347 | 1347 | ||
| 1348 | var system_libs: std.StringArrayHashMapUnmanaged(void) = .{}; | 1348 | var system_libs: std.StringArrayHashMapUnmanaged(void) = .{}; |
| 1349 | errdefer system_libs.deinit(gpa); | 1349 | errdefer system_libs.deinit(gpa); |
| 1350 | try system_libs.ensureCapacity(gpa, options.system_libs.len); | 1350 | try system_libs.ensureTotalCapacity(gpa, options.system_libs.len); |
| 1351 | for (options.system_libs) |lib_name| { | 1351 | for (options.system_libs) |lib_name| { |
| 1352 | system_libs.putAssumeCapacity(lib_name, {}); | 1352 | system_libs.putAssumeCapacity(lib_name, {}); |
| 1353 | } | 1353 | } |
| ... | @@ -1483,7 +1483,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1483,7 +1483,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1483 | errdefer comp.astgen_wait_group.deinit(); | 1483 | errdefer comp.astgen_wait_group.deinit(); |
| 1484 | 1484 | ||
| 1485 | // Add a `CObject` for each `c_source_files`. | 1485 | // Add a `CObject` for each `c_source_files`. |
| 1486 | try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len); | 1486 | try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len); |
| 1487 | for (options.c_source_files) |c_source_file| { | 1487 | for (options.c_source_files) |c_source_file| { |
| 1488 | const c_object = try gpa.create(CObject); | 1488 | const c_object = try gpa.create(CObject); |
| 1489 | errdefer gpa.destroy(c_object); | 1489 | errdefer gpa.destroy(c_object); |
| ... | @@ -3084,7 +3084,7 @@ pub fn addCCArgs( | ... | @@ -3084,7 +3084,7 @@ pub fn addCCArgs( |
| 3084 | 3084 | ||
| 3085 | // It would be really nice if there was a more compact way to communicate this info to Clang. | 3085 | // It would be really nice if there was a more compact way to communicate this info to Clang. |
| 3086 | const all_features_list = target.cpu.arch.allFeaturesList(); | 3086 | const all_features_list = target.cpu.arch.allFeaturesList(); |
| 3087 | try argv.ensureCapacity(argv.items.len + all_features_list.len * 4); | 3087 | try argv.ensureUnusedCapacity(all_features_list.len * 4); |
| 3088 | for (all_features_list) |feature, index_usize| { | 3088 | for (all_features_list) |feature, index_usize| { |
| 3089 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); | 3089 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); |
| 3090 | const is_enabled = target.cpu.features.isEnabled(index); | 3090 | const is_enabled = target.cpu.features.isEnabled(index); |
| ... | @@ -3334,7 +3334,7 @@ fn failCObjWithOwnedErrorMsg( | ... | @@ -3334,7 +3334,7 @@ fn failCObjWithOwnedErrorMsg( |
| 3334 | defer lock.release(); | 3334 | defer lock.release(); |
| 3335 | { | 3335 | { |
| 3336 | errdefer err_msg.destroy(comp.gpa); | 3336 | errdefer err_msg.destroy(comp.gpa); |
| 3337 | try comp.failed_c_objects.ensureCapacity(comp.gpa, comp.failed_c_objects.count() + 1); | 3337 | try comp.failed_c_objects.ensureUnusedCapacity(comp.gpa, 1); |
| 3338 | } | 3338 | } |
| 3339 | comp.failed_c_objects.putAssumeCapacityNoClobber(c_object, err_msg); | 3339 | comp.failed_c_objects.putAssumeCapacityNoClobber(c_object, err_msg); |
| 3340 | } | 3340 | } |
| ... | @@ -3585,7 +3585,7 @@ fn detectLibCIncludeDirs( | ... | @@ -3585,7 +3585,7 @@ fn detectLibCIncludeDirs( |
| 3585 | 3585 | ||
| 3586 | fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs { | 3586 | fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs { |
| 3587 | var list = std.ArrayList([]const u8).init(arena); | 3587 | var list = std.ArrayList([]const u8).init(arena); |
| 3588 | try list.ensureCapacity(4); | 3588 | try list.ensureTotalCapacity(4); |
| 3589 | 3589 | ||
| 3590 | list.appendAssumeCapacity(lci.include_dir.?); | 3590 | list.appendAssumeCapacity(lci.include_dir.?); |
| 3591 | 3591 | ||
| ... | @@ -3692,7 +3692,7 @@ fn setMiscFailure( | ... | @@ -3692,7 +3692,7 @@ fn setMiscFailure( |
| 3692 | comptime format: []const u8, | 3692 | comptime format: []const u8, |
| 3693 | args: anytype, | 3693 | args: anytype, |
| 3694 | ) Allocator.Error!void { | 3694 | ) Allocator.Error!void { |
| 3695 | try comp.misc_failures.ensureCapacity(comp.gpa, comp.misc_failures.count() + 1); | 3695 | try comp.misc_failures.ensureUnusedCapacity(comp.gpa, 1); |
| 3696 | const msg = try std.fmt.allocPrint(comp.gpa, format, args); | 3696 | const msg = try std.fmt.allocPrint(comp.gpa, format, args); |
| 3697 | comp.misc_failures.putAssumeCapacityNoClobber(tag, .{ .msg = msg }); | 3697 | comp.misc_failures.putAssumeCapacityNoClobber(tag, .{ .msg = msg }); |
| 3698 | } | 3698 | } |
| ... | @@ -4027,7 +4027,7 @@ fn buildOutputFromZig( | ... | @@ -4027,7 +4027,7 @@ fn buildOutputFromZig( |
| 4027 | defer if (!keep_errors) errors.deinit(sub_compilation.gpa); | 4027 | defer if (!keep_errors) errors.deinit(sub_compilation.gpa); |
| 4028 | 4028 | ||
| 4029 | if (errors.list.len != 0) { | 4029 | if (errors.list.len != 0) { |
| 4030 | try comp.misc_failures.ensureCapacity(comp.gpa, comp.misc_failures.count() + 1); | 4030 | try comp.misc_failures.ensureUnusedCapacity(comp.gpa, 1); |
| 4031 | comp.misc_failures.putAssumeCapacityNoClobber(misc_task_tag, .{ | 4031 | comp.misc_failures.putAssumeCapacityNoClobber(misc_task_tag, .{ |
| 4032 | .msg = try std.fmt.allocPrint(comp.gpa, "sub-compilation of {s} failed", .{ | 4032 | .msg = try std.fmt.allocPrint(comp.gpa, "sub-compilation of {s} failed", .{ |
| 4033 | @tagName(misc_task_tag), | 4033 | @tagName(misc_task_tag), |
| ... | @@ -4459,7 +4459,7 @@ pub fn build_crt_file( | ... | @@ -4459,7 +4459,7 @@ pub fn build_crt_file( |
| 4459 | 4459 | ||
| 4460 | try sub_compilation.updateSubCompilation(); | 4460 | try sub_compilation.updateSubCompilation(); |
| 4461 | 4461 | ||
| 4462 | try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1); | 4462 | try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1); |
| 4463 | 4463 | ||
| 4464 | comp.crt_files.putAssumeCapacityNoClobber(basename, .{ | 4464 | comp.crt_files.putAssumeCapacityNoClobber(basename, .{ |
| 4465 | .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{ | 4465 | .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{ |
src/Liveness.zig+1-1| ... | @@ -454,7 +454,7 @@ fn analyzeInst( | ... | @@ -454,7 +454,7 @@ fn analyzeInst( |
| 454 | } | 454 | } |
| 455 | // Now we have to correctly populate new_set. | 455 | // Now we have to correctly populate new_set. |
| 456 | if (new_set) |ns| { | 456 | if (new_set) |ns| { |
| 457 | try ns.ensureCapacity(gpa, @intCast(u32, ns.count() + then_table.count() + else_table.count())); | 457 | try ns.ensureUnusedCapacity(gpa, @intCast(u32, then_table.count() + else_table.count())); |
| 458 | var it = then_table.keyIterator(); | 458 | var it = then_table.keyIterator(); |
| 459 | while (it.next()) |key| { | 459 | while (it.next()) |key| { |
| 460 | _ = ns.putAssumeCapacity(key.*, {}); | 460 | _ = ns.putAssumeCapacity(key.*, {}); |
src/Module.zig+2-2| ... | @@ -3504,7 +3504,7 @@ pub fn scanNamespace( | ... | @@ -3504,7 +3504,7 @@ pub fn scanNamespace( |
| 3504 | const zir = namespace.file_scope.zir; | 3504 | const zir = namespace.file_scope.zir; |
| 3505 | 3505 | ||
| 3506 | try mod.comp.work_queue.ensureUnusedCapacity(decls_len); | 3506 | try mod.comp.work_queue.ensureUnusedCapacity(decls_len); |
| 3507 | try namespace.decls.ensureCapacity(gpa, decls_len); | 3507 | try namespace.decls.ensureTotalCapacity(gpa, decls_len); |
| 3508 | 3508 | ||
| 3509 | const bit_bags_count = std.math.divCeil(usize, decls_len, 8) catch unreachable; | 3509 | const bit_bags_count = std.math.divCeil(usize, decls_len, 8) catch unreachable; |
| 3510 | var extra_index = extra_start + bit_bags_count; | 3510 | var extra_index = extra_start + bit_bags_count; |
| ... | @@ -4071,7 +4071,7 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged | ... | @@ -4071,7 +4071,7 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged |
| 4071 | } | 4071 | } |
| 4072 | 4072 | ||
| 4073 | errdefer assert(mod.global_error_set.remove(name)); | 4073 | errdefer assert(mod.global_error_set.remove(name)); |
| 4074 | try mod.error_name_list.ensureCapacity(mod.gpa, mod.error_name_list.items.len + 1); | 4074 | try mod.error_name_list.ensureUnusedCapacity(mod.gpa, 1); |
| 4075 | gop.key_ptr.* = try mod.gpa.dupe(u8, name); | 4075 | gop.key_ptr.* = try mod.gpa.dupe(u8, name); |
| 4076 | gop.value_ptr.* = @intCast(ErrorInt, mod.error_name_list.items.len); | 4076 | gop.value_ptr.* = @intCast(ErrorInt, mod.error_name_list.items.len); |
| 4077 | mod.error_name_list.appendAssumeCapacity(gop.key_ptr.*); | 4077 | mod.error_name_list.appendAssumeCapacity(gop.key_ptr.*); |
src/Package.zig+1-1| ... | @@ -111,7 +111,7 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void { | ... | @@ -111,7 +111,7 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void { |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void { | 113 | pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void { |
| 114 | try pkg.table.ensureCapacity(gpa, pkg.table.count() + 1); | 114 | try pkg.table.ensureUnusedCapacity(gpa, 1); |
| 115 | const name_dupe = try mem.dupe(gpa, u8, name); | 115 | const name_dupe = try mem.dupe(gpa, u8, name); |
| 116 | pkg.table.putAssumeCapacityNoClobber(name_dupe, package); | 116 | pkg.table.putAssumeCapacityNoClobber(name_dupe, package); |
| 117 | } | 117 | } |
src/Sema.zig+4-4| ... | @@ -1130,7 +1130,7 @@ fn zirEnumDecl( | ... | @@ -1130,7 +1130,7 @@ fn zirEnumDecl( |
| 1130 | const body_end = extra_index; | 1130 | const body_end = extra_index; |
| 1131 | extra_index += bit_bags_count; | 1131 | extra_index += bit_bags_count; |
| 1132 | 1132 | ||
| 1133 | try enum_obj.fields.ensureCapacity(&new_decl_arena.allocator, fields_len); | 1133 | try enum_obj.fields.ensureTotalCapacity(&new_decl_arena.allocator, fields_len); |
| 1134 | const any_values = for (sema.code.extra[body_end..][0..bit_bags_count]) |bag| { | 1134 | const any_values = for (sema.code.extra[body_end..][0..bit_bags_count]) |bag| { |
| 1135 | if (bag != 0) break true; | 1135 | if (bag != 0) break true; |
| 1136 | } else false; | 1136 | } else false; |
| ... | @@ -3484,7 +3484,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -3484,7 +3484,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3484 | }, | 3484 | }, |
| 3485 | .error_set => { | 3485 | .error_set => { |
| 3486 | const lhs_set = lhs_ty.castTag(.error_set).?.data; | 3486 | const lhs_set = lhs_ty.castTag(.error_set).?.data; |
| 3487 | try set.ensureCapacity(sema.gpa, set.count() + lhs_set.names_len); | 3487 | try set.ensureUnusedCapacity(sema.gpa, lhs_set.names_len); |
| 3488 | for (lhs_set.names_ptr[0..lhs_set.names_len]) |name| { | 3488 | for (lhs_set.names_ptr[0..lhs_set.names_len]) |name| { |
| 3489 | set.putAssumeCapacityNoClobber(name, {}); | 3489 | set.putAssumeCapacityNoClobber(name, {}); |
| 3490 | } | 3490 | } |
| ... | @@ -3498,7 +3498,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -3498,7 +3498,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3498 | }, | 3498 | }, |
| 3499 | .error_set => { | 3499 | .error_set => { |
| 3500 | const rhs_set = rhs_ty.castTag(.error_set).?.data; | 3500 | const rhs_set = rhs_ty.castTag(.error_set).?.data; |
| 3501 | try set.ensureCapacity(sema.gpa, set.count() + rhs_set.names_len); | 3501 | try set.ensureUnusedCapacity(sema.gpa, rhs_set.names_len); |
| 3502 | for (rhs_set.names_ptr[0..rhs_set.names_len]) |name| { | 3502 | for (rhs_set.names_ptr[0..rhs_set.names_len]) |name| { |
| 3503 | set.putAssumeCapacity(name, {}); | 3503 | set.putAssumeCapacity(name, {}); |
| 3504 | } | 3504 | } |
| ... | @@ -10361,7 +10361,7 @@ fn analyzeUnionFields( | ... | @@ -10361,7 +10361,7 @@ fn analyzeUnionFields( |
| 10361 | var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa); | 10361 | var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa); |
| 10362 | defer union_obj.owner_decl.value_arena.?.* = decl_arena.state; | 10362 | defer union_obj.owner_decl.value_arena.?.* = decl_arena.state; |
| 10363 | 10363 | ||
| 10364 | try union_obj.fields.ensureCapacity(&decl_arena.allocator, fields_len); | 10364 | try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len); |
| 10365 | 10365 | ||
| 10366 | if (body.len != 0) { | 10366 | if (body.len != 0) { |
| 10367 | _ = try sema.analyzeBody(block, body); | 10367 | _ = try sema.analyzeBody(block, body); |
src/codegen.zig+17-17| ... | @@ -141,7 +141,7 @@ pub fn generateSymbol( | ... | @@ -141,7 +141,7 @@ pub fn generateSymbol( |
| 141 | // TODO populate .debug_info for the array | 141 | // TODO populate .debug_info for the array |
| 142 | if (typed_value.val.castTag(.bytes)) |payload| { | 142 | if (typed_value.val.castTag(.bytes)) |payload| { |
| 143 | if (typed_value.ty.sentinel()) |sentinel| { | 143 | if (typed_value.ty.sentinel()) |sentinel| { |
| 144 | try code.ensureCapacity(code.items.len + payload.data.len + 1); | 144 | try code.ensureUnusedCapacity(payload.data.len + 1); |
| 145 | code.appendSliceAssumeCapacity(payload.data); | 145 | code.appendSliceAssumeCapacity(payload.data); |
| 146 | switch (try generateSymbol(bin_file, src_loc, .{ | 146 | switch (try generateSymbol(bin_file, src_loc, .{ |
| 147 | .ty = typed_value.ty.elemType(), | 147 | .ty = typed_value.ty.elemType(), |
| ... | @@ -568,7 +568,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -568,7 +568,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 568 | fn gen(self: *Self) !void { | 568 | fn gen(self: *Self) !void { |
| 569 | switch (arch) { | 569 | switch (arch) { |
| 570 | .x86_64 => { | 570 | .x86_64 => { |
| 571 | try self.code.ensureCapacity(self.code.items.len + 11); | 571 | try self.code.ensureUnusedCapacity(11); |
| 572 | 572 | ||
| 573 | const cc = self.fn_type.fnCallingConvention(); | 573 | const cc = self.fn_type.fnCallingConvention(); |
| 574 | if (cc != .Naked) { | 574 | if (cc != .Naked) { |
| ... | @@ -607,7 +607,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -607,7 +607,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 607 | // Important to be after the possible self.code.items.len -= 5 above. | 607 | // Important to be after the possible self.code.items.len -= 5 above. |
| 608 | try self.dbgSetEpilogueBegin(); | 608 | try self.dbgSetEpilogueBegin(); |
| 609 | 609 | ||
| 610 | try self.code.ensureCapacity(self.code.items.len + 9); | 610 | try self.code.ensureUnusedCapacity(9); |
| 611 | // add rsp, x | 611 | // add rsp, x |
| 612 | if (aligned_stack_end > math.maxInt(i8)) { | 612 | if (aligned_stack_end > math.maxInt(i8)) { |
| 613 | // example: 48 81 c4 ff ff ff 7f add rsp,0x7fffffff | 613 | // example: 48 81 c4 ff ff ff 7f add rsp,0x7fffffff |
| ... | @@ -1960,7 +1960,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -1960,7 +1960,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 1960 | // | 1960 | // |
| 1961 | // TODO: make this algorithm less bad | 1961 | // TODO: make this algorithm less bad |
| 1962 | 1962 | ||
| 1963 | try self.code.ensureCapacity(self.code.items.len + 8); | 1963 | try self.code.ensureUnusedCapacity(8); |
| 1964 | 1964 | ||
| 1965 | const lhs = try self.resolveInst(op_lhs); | 1965 | const lhs = try self.resolveInst(op_lhs); |
| 1966 | const rhs = try self.resolveInst(op_rhs); | 1966 | const rhs = try self.resolveInst(op_rhs); |
| ... | @@ -2447,13 +2447,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2447,13 +2447,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2447 | .register => |reg| { | 2447 | .register => |reg| { |
| 2448 | switch (self.debug_output) { | 2448 | switch (self.debug_output) { |
| 2449 | .dwarf => |dbg_out| { | 2449 | .dwarf => |dbg_out| { |
| 2450 | try dbg_out.dbg_info.ensureCapacity(dbg_out.dbg_info.items.len + 3); | 2450 | try dbg_out.dbg_info.ensureUnusedCapacity(3); |
| 2451 | dbg_out.dbg_info.appendAssumeCapacity(link.File.Elf.abbrev_parameter); | 2451 | dbg_out.dbg_info.appendAssumeCapacity(link.File.Elf.abbrev_parameter); |
| 2452 | dbg_out.dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | 2452 | dbg_out.dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc |
| 2453 | 1, // ULEB128 dwarf expression length | 2453 | 1, // ULEB128 dwarf expression length |
| 2454 | reg.dwarfLocOp(), | 2454 | reg.dwarfLocOp(), |
| 2455 | }); | 2455 | }); |
| 2456 | try dbg_out.dbg_info.ensureCapacity(dbg_out.dbg_info.items.len + 5 + name_with_null.len); | 2456 | try dbg_out.dbg_info.ensureUnusedCapacity(5 + name_with_null.len); |
| 2457 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 | 2457 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 |
| 2458 | dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | 2458 | dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 2459 | }, | 2459 | }, |
| ... | @@ -2484,7 +2484,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2484,7 +2484,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2484 | try dbg_out.dbg_info.append(DW.OP.breg11); | 2484 | try dbg_out.dbg_info.append(DW.OP.breg11); |
| 2485 | try leb128.writeILEB128(dbg_out.dbg_info.writer(), adjusted_stack_offset); | 2485 | try leb128.writeILEB128(dbg_out.dbg_info.writer(), adjusted_stack_offset); |
| 2486 | 2486 | ||
| 2487 | try dbg_out.dbg_info.ensureCapacity(dbg_out.dbg_info.items.len + 5 + name_with_null.len); | 2487 | try dbg_out.dbg_info.ensureUnusedCapacity(5 + name_with_null.len); |
| 2488 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 | 2488 | try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4 |
| 2489 | dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string | 2489 | dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 2490 | }, | 2490 | }, |
| ... | @@ -2626,7 +2626,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2626,7 +2626,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2626 | unreachable; | 2626 | unreachable; |
| 2627 | 2627 | ||
| 2628 | // ff 14 25 xx xx xx xx call [addr] | 2628 | // ff 14 25 xx xx xx xx call [addr] |
| 2629 | try self.code.ensureCapacity(self.code.items.len + 7); | 2629 | try self.code.ensureUnusedCapacity(7); |
| 2630 | self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 }); | 2630 | self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 }); |
| 2631 | mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), got_addr); | 2631 | mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), got_addr); |
| 2632 | } else if (func_value.castTag(.extern_fn)) |_| { | 2632 | } else if (func_value.castTag(.extern_fn)) |_| { |
| ... | @@ -2839,7 +2839,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2839,7 +2839,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2839 | .memory = func.owner_decl.link.macho.local_sym_index, | 2839 | .memory = func.owner_decl.link.macho.local_sym_index, |
| 2840 | }); | 2840 | }); |
| 2841 | // callq *%rax | 2841 | // callq *%rax |
| 2842 | try self.code.ensureCapacity(self.code.items.len + 2); | 2842 | try self.code.ensureUnusedCapacity(2); |
| 2843 | self.code.appendSliceAssumeCapacity(&[2]u8{ 0xff, 0xd0 }); | 2843 | self.code.appendSliceAssumeCapacity(&[2]u8{ 0xff, 0xd0 }); |
| 2844 | }, | 2844 | }, |
| 2845 | .aarch64 => { | 2845 | .aarch64 => { |
| ... | @@ -2858,7 +2858,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2858,7 +2858,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2858 | switch (arch) { | 2858 | switch (arch) { |
| 2859 | .x86_64 => { | 2859 | .x86_64 => { |
| 2860 | // callq | 2860 | // callq |
| 2861 | try self.code.ensureCapacity(self.code.items.len + 5); | 2861 | try self.code.ensureUnusedCapacity(5); |
| 2862 | self.code.appendSliceAssumeCapacity(&[5]u8{ 0xe8, 0x0, 0x0, 0x0, 0x0 }); | 2862 | self.code.appendSliceAssumeCapacity(&[5]u8{ 0xe8, 0x0, 0x0, 0x0, 0x0 }); |
| 2863 | break :blk @intCast(u32, self.code.items.len) - 4; | 2863 | break :blk @intCast(u32, self.code.items.len) - 4; |
| 2864 | }, | 2864 | }, |
| ... | @@ -2932,7 +2932,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2932,7 +2932,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2932 | const got_addr = p9.bases.data; | 2932 | const got_addr = p9.bases.data; |
| 2933 | const got_index = func_payload.data.owner_decl.link.plan9.got_index.?; | 2933 | const got_index = func_payload.data.owner_decl.link.plan9.got_index.?; |
| 2934 | // ff 14 25 xx xx xx xx call [addr] | 2934 | // ff 14 25 xx xx xx xx call [addr] |
| 2935 | try self.code.ensureCapacity(self.code.items.len + 7); | 2935 | try self.code.ensureUnusedCapacity(7); |
| 2936 | self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 }); | 2936 | self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 }); |
| 2937 | const fn_got_addr = got_addr + got_index * ptr_bytes; | 2937 | const fn_got_addr = got_addr + got_index * ptr_bytes; |
| 2938 | mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), @intCast(u32, fn_got_addr)); | 2938 | mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), @intCast(u32, fn_got_addr)); |
| ... | @@ -3075,7 +3075,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -3075,7 +3075,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 3075 | const rhs = try self.resolveInst(bin_op.rhs); | 3075 | const rhs = try self.resolveInst(bin_op.rhs); |
| 3076 | const result: MCValue = switch (arch) { | 3076 | const result: MCValue = switch (arch) { |
| 3077 | .x86_64 => result: { | 3077 | .x86_64 => result: { |
| 3078 | try self.code.ensureCapacity(self.code.items.len + 8); | 3078 | try self.code.ensureUnusedCapacity(8); |
| 3079 | 3079 | ||
| 3080 | // There are 2 operands, destination and source. | 3080 | // There are 2 operands, destination and source. |
| 3081 | // Either one, but not both, can be a memory operand. | 3081 | // Either one, but not both, can be a memory operand. |
| ... | @@ -3159,7 +3159,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -3159,7 +3159,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 3159 | 3159 | ||
| 3160 | const reloc: Reloc = switch (arch) { | 3160 | const reloc: Reloc = switch (arch) { |
| 3161 | .i386, .x86_64 => reloc: { | 3161 | .i386, .x86_64 => reloc: { |
| 3162 | try self.code.ensureCapacity(self.code.items.len + 6); | 3162 | try self.code.ensureUnusedCapacity(6); |
| 3163 | 3163 | ||
| 3164 | const opcode: u8 = switch (cond) { | 3164 | const opcode: u8 = switch (cond) { |
| 3165 | .compare_flags_signed => |cmp_op| blk: { | 3165 | .compare_flags_signed => |cmp_op| blk: { |
| ... | @@ -3519,7 +3519,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -3519,7 +3519,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 3519 | fn jump(self: *Self, index: usize) !void { | 3519 | fn jump(self: *Self, index: usize) !void { |
| 3520 | switch (arch) { | 3520 | switch (arch) { |
| 3521 | .i386, .x86_64 => { | 3521 | .i386, .x86_64 => { |
| 3522 | try self.code.ensureCapacity(self.code.items.len + 5); | 3522 | try self.code.ensureUnusedCapacity(5); |
| 3523 | if (math.cast(i8, @intCast(i32, index) - (@intCast(i32, self.code.items.len + 2)))) |delta| { | 3523 | if (math.cast(i8, @intCast(i32, index) - (@intCast(i32, self.code.items.len + 2)))) |delta| { |
| 3524 | self.code.appendAssumeCapacity(0xeb); // jmp rel8 | 3524 | self.code.appendAssumeCapacity(0xeb); // jmp rel8 |
| 3525 | self.code.appendAssumeCapacity(@bitCast(u8, delta)); | 3525 | self.code.appendAssumeCapacity(@bitCast(u8, delta)); |
| ... | @@ -3657,7 +3657,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -3657,7 +3657,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 3657 | const block_data = self.blocks.getPtr(block).?; | 3657 | const block_data = self.blocks.getPtr(block).?; |
| 3658 | 3658 | ||
| 3659 | // Emit a jump with a relocation. It will be patched up after the block ends. | 3659 | // Emit a jump with a relocation. It will be patched up after the block ends. |
| 3660 | try block_data.relocs.ensureCapacity(self.gpa, block_data.relocs.items.len + 1); | 3660 | try block_data.relocs.ensureUnusedCapacity(self.gpa, 1); |
| 3661 | 3661 | ||
| 3662 | switch (arch) { | 3662 | switch (arch) { |
| 3663 | .i386, .x86_64 => { | 3663 | .i386, .x86_64 => { |
| ... | @@ -4041,7 +4041,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -4041,7 +4041,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 4041 | if (adj_off > 128) { | 4041 | if (adj_off > 128) { |
| 4042 | return self.fail("TODO implement set stack variable with large stack offset", .{}); | 4042 | return self.fail("TODO implement set stack variable with large stack offset", .{}); |
| 4043 | } | 4043 | } |
| 4044 | try self.code.ensureCapacity(self.code.items.len + 8); | 4044 | try self.code.ensureUnusedCapacity(8); |
| 4045 | switch (abi_size) { | 4045 | switch (abi_size) { |
| 4046 | 1 => { | 4046 | 1 => { |
| 4047 | return self.fail("TODO implement set abi_size=1 stack variable with immediate", .{}); | 4047 | return self.fail("TODO implement set abi_size=1 stack variable with immediate", .{}); |
| ... | @@ -4067,7 +4067,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -4067,7 +4067,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 4067 | 4067 | ||
| 4068 | // 64 bit write to memory would take two mov's anyways so we | 4068 | // 64 bit write to memory would take two mov's anyways so we |
| 4069 | // insted just use two 32 bit writes to avoid register allocation | 4069 | // insted just use two 32 bit writes to avoid register allocation |
| 4070 | try self.code.ensureCapacity(self.code.items.len + 14); | 4070 | try self.code.ensureUnusedCapacity(14); |
| 4071 | var buf: [8]u8 = undefined; | 4071 | var buf: [8]u8 = undefined; |
| 4072 | mem.writeIntLittle(u64, &buf, x_big); | 4072 | mem.writeIntLittle(u64, &buf, x_big); |
| 4073 | 4073 |
src/codegen/spirv.zig+1-1| ... | @@ -629,7 +629,7 @@ pub const DeclGen = struct { | ... | @@ -629,7 +629,7 @@ pub const DeclGen = struct { |
| 629 | const params = decl.ty.fnParamLen(); | 629 | const params = decl.ty.fnParamLen(); |
| 630 | var i: usize = 0; | 630 | var i: usize = 0; |
| 631 | 631 | ||
| 632 | try self.args.ensureCapacity(params); | 632 | try self.args.ensureTotalCapacity(params); |
| 633 | while (i < params) : (i += 1) { | 633 | while (i < params) : (i += 1) { |
| 634 | const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?; | 634 | const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?; |
| 635 | const arg_result_id = self.spv.allocResultId(); | 635 | const arg_result_id = self.spv.allocResultId(); |
src/libcxx.zig+2-2| ... | @@ -108,7 +108,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { | ... | @@ -108,7 +108,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { |
| 108 | const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); | 108 | const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); |
| 109 | const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); | 109 | const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); |
| 110 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); | 110 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 111 | try c_source_files.ensureCapacity(libcxx_files.len); | 111 | try c_source_files.ensureTotalCapacity(libcxx_files.len); |
| 112 | 112 | ||
| 113 | for (libcxx_files) |cxx_src| { | 113 | for (libcxx_files) |cxx_src| { |
| 114 | var cflags = std.ArrayList([]const u8).init(arena); | 114 | var cflags = std.ArrayList([]const u8).init(arena); |
| ... | @@ -246,7 +246,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { | ... | @@ -246,7 +246,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { |
| 246 | const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); | 246 | const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); |
| 247 | const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); | 247 | const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); |
| 248 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); | 248 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 249 | try c_source_files.ensureCapacity(libcxxabi_files.len); | 249 | try c_source_files.ensureTotalCapacity(libcxxabi_files.len); |
| 250 | 250 | ||
| 251 | for (libcxxabi_files) |cxxabi_src| { | 251 | for (libcxxabi_files) |cxxabi_src| { |
| 252 | var cflags = std.ArrayList([]const u8).init(arena); | 252 | var cflags = std.ArrayList([]const u8).init(arena); |
src/libtsan.zig+6-6| ... | @@ -34,7 +34,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -34,7 +34,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); | 36 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 37 | try c_source_files.ensureCapacity(c_source_files.items.len + tsan_sources.len); | 37 | try c_source_files.ensureUnusedCapacity(tsan_sources.len); |
| 38 | 38 | ||
| 39 | const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"tsan"}); | 39 | const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"tsan"}); |
| 40 | for (tsan_sources) |tsan_src| { | 40 | for (tsan_sources) |tsan_src| { |
| ... | @@ -58,7 +58,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -58,7 +58,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 58 | &darwin_tsan_sources | 58 | &darwin_tsan_sources |
| 59 | else | 59 | else |
| 60 | &unix_tsan_sources; | 60 | &unix_tsan_sources; |
| 61 | try c_source_files.ensureCapacity(c_source_files.items.len + platform_tsan_sources.len); | 61 | try c_source_files.ensureUnusedCapacity(platform_tsan_sources.len); |
| 62 | for (platform_tsan_sources) |tsan_src| { | 62 | for (platform_tsan_sources) |tsan_src| { |
| 63 | var cflags = std.ArrayList([]const u8).init(arena); | 63 | var cflags = std.ArrayList([]const u8).init(arena); |
| 64 | 64 | ||
| ... | @@ -96,7 +96,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -96,7 +96,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 96 | }); | 96 | }); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | try c_source_files.ensureCapacity(c_source_files.items.len + sanitizer_common_sources.len); | 99 | try c_source_files.ensureUnusedCapacity(sanitizer_common_sources.len); |
| 100 | const sanitizer_common_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 100 | const sanitizer_common_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 101 | "tsan", "sanitizer_common", | 101 | "tsan", "sanitizer_common", |
| 102 | }); | 102 | }); |
| ... | @@ -123,7 +123,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -123,7 +123,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 123 | &sanitizer_libcdep_sources | 123 | &sanitizer_libcdep_sources |
| 124 | else | 124 | else |
| 125 | &sanitizer_nolibc_sources; | 125 | &sanitizer_nolibc_sources; |
| 126 | try c_source_files.ensureCapacity(c_source_files.items.len + to_c_or_not_to_c_sources.len); | 126 | try c_source_files.ensureUnusedCapacity(to_c_or_not_to_c_sources.len); |
| 127 | for (to_c_or_not_to_c_sources) |c_src| { | 127 | for (to_c_or_not_to_c_sources) |c_src| { |
| 128 | var cflags = std.ArrayList([]const u8).init(arena); | 128 | var cflags = std.ArrayList([]const u8).init(arena); |
| 129 | 129 | ||
| ... | @@ -143,7 +143,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -143,7 +143,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 143 | }); | 143 | }); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | try c_source_files.ensureCapacity(c_source_files.items.len + sanitizer_symbolizer_sources.len); | 146 | try c_source_files.ensureUnusedCapacity(sanitizer_symbolizer_sources.len); |
| 147 | for (sanitizer_symbolizer_sources) |c_src| { | 147 | for (sanitizer_symbolizer_sources) |c_src| { |
| 148 | var cflags = std.ArrayList([]const u8).init(arena); | 148 | var cflags = std.ArrayList([]const u8).init(arena); |
| 149 | 149 | ||
| ... | @@ -168,7 +168,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -168,7 +168,7 @@ pub fn buildTsan(comp: *Compilation) !void { |
| 168 | &[_][]const u8{"interception"}, | 168 | &[_][]const u8{"interception"}, |
| 169 | ); | 169 | ); |
| 170 | 170 | ||
| 171 | try c_source_files.ensureCapacity(c_source_files.items.len + interception_sources.len); | 171 | try c_source_files.ensureUnusedCapacity(interception_sources.len); |
| 172 | for (interception_sources) |c_src| { | 172 | for (interception_sources) |c_src| { |
| 173 | var cflags = std.ArrayList([]const u8).init(arena); | 173 | var cflags = std.ArrayList([]const u8).init(arena); |
| 174 | 174 |
src/link.zig+1-1| ... | @@ -635,7 +635,7 @@ pub const File = struct { | ... | @@ -635,7 +635,7 @@ pub const File = struct { |
| 635 | var object_files = std.ArrayList([*:0]const u8).init(base.allocator); | 635 | var object_files = std.ArrayList([*:0]const u8).init(base.allocator); |
| 636 | defer object_files.deinit(); | 636 | defer object_files.deinit(); |
| 637 | 637 | ||
| 638 | try object_files.ensureCapacity(base.options.objects.len + comp.c_object_table.count() + 2); | 638 | try object_files.ensureTotalCapacity(base.options.objects.len + comp.c_object_table.count() + 2); |
| 639 | for (base.options.objects) |obj_path| { | 639 | for (base.options.objects) |obj_path| { |
| 640 | object_files.appendAssumeCapacity(try arena.dupeZ(u8, obj_path)); | 640 | object_files.appendAssumeCapacity(try arena.dupeZ(u8, obj_path)); |
| 641 | } | 641 | } |
src/link/C.zig+3-3| ... | @@ -197,7 +197,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { | ... | @@ -197,7 +197,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { |
| 197 | defer all_buffers.deinit(); | 197 | defer all_buffers.deinit(); |
| 198 | 198 | ||
| 199 | // This is at least enough until we get to the function bodies without error handling. | 199 | // This is at least enough until we get to the function bodies without error handling. |
| 200 | try all_buffers.ensureCapacity(self.decl_table.count() + 2); | 200 | try all_buffers.ensureTotalCapacity(self.decl_table.count() + 2); |
| 201 | 201 | ||
| 202 | var file_size: u64 = zig_h.len; | 202 | var file_size: u64 = zig_h.len; |
| 203 | all_buffers.appendAssumeCapacity(.{ | 203 | all_buffers.appendAssumeCapacity(.{ |
| ... | @@ -258,7 +258,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { | ... | @@ -258,7 +258,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { |
| 258 | file_size += err_typedef_buf.items.len; | 258 | file_size += err_typedef_buf.items.len; |
| 259 | 259 | ||
| 260 | // Now the function bodies. | 260 | // Now the function bodies. |
| 261 | try all_buffers.ensureCapacity(all_buffers.items.len + fn_count); | 261 | try all_buffers.ensureUnusedCapacity(fn_count); |
| 262 | for (self.decl_table.keys()) |decl| { | 262 | for (self.decl_table.keys()) |decl| { |
| 263 | if (!decl.has_tv) continue; | 263 | if (!decl.has_tv) continue; |
| 264 | if (decl.val.castTag(.function)) |_| { | 264 | if (decl.val.castTag(.function)) |_| { |
| ... | @@ -286,7 +286,7 @@ pub fn flushEmitH(module: *Module) !void { | ... | @@ -286,7 +286,7 @@ pub fn flushEmitH(module: *Module) !void { |
| 286 | var all_buffers = std.ArrayList(std.os.iovec_const).init(module.gpa); | 286 | var all_buffers = std.ArrayList(std.os.iovec_const).init(module.gpa); |
| 287 | defer all_buffers.deinit(); | 287 | defer all_buffers.deinit(); |
| 288 | 288 | ||
| 289 | try all_buffers.ensureCapacity(emit_h.decl_table.count() + 1); | 289 | try all_buffers.ensureTotalCapacity(emit_h.decl_table.count() + 1); |
| 290 | 290 | ||
| 291 | var file_size: u64 = zig_h.len; | 291 | var file_size: u64 = zig_h.len; |
| 292 | all_buffers.appendAssumeCapacity(.{ | 292 | all_buffers.appendAssumeCapacity(.{ |
src/link/Coff.zig+3-3| ... | @@ -418,7 +418,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff { | ... | @@ -418,7 +418,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff { |
| 418 | pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void { | 418 | pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void { |
| 419 | if (self.llvm_object) |_| return; | 419 | if (self.llvm_object) |_| return; |
| 420 | 420 | ||
| 421 | try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1); | 421 | try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1); |
| 422 | 422 | ||
| 423 | if (self.offset_table_free_list.popOrNull()) |i| { | 423 | if (self.offset_table_free_list.popOrNull()) |i| { |
| 424 | decl.link.coff.offset_table_index = i; | 424 | decl.link.coff.offset_table_index = i; |
| ... | @@ -793,7 +793,7 @@ pub fn updateDeclExports( | ... | @@ -793,7 +793,7 @@ pub fn updateDeclExports( |
| 793 | for (exports) |exp| { | 793 | for (exports) |exp| { |
| 794 | if (exp.options.section) |section_name| { | 794 | if (exp.options.section) |section_name| { |
| 795 | if (!mem.eql(u8, section_name, ".text")) { | 795 | if (!mem.eql(u8, section_name, ".text")) { |
| 796 | try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1); | 796 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); |
| 797 | module.failed_exports.putAssumeCapacityNoClobber( | 797 | module.failed_exports.putAssumeCapacityNoClobber( |
| 798 | exp, | 798 | exp, |
| 799 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}), | 799 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}), |
| ... | @@ -804,7 +804,7 @@ pub fn updateDeclExports( | ... | @@ -804,7 +804,7 @@ pub fn updateDeclExports( |
| 804 | if (mem.eql(u8, exp.options.name, "_start")) { | 804 | if (mem.eql(u8, exp.options.name, "_start")) { |
| 805 | self.entry_addr = decl.link.coff.getVAddr(self.*) - default_image_base; | 805 | self.entry_addr = decl.link.coff.getVAddr(self.*) - default_image_base; |
| 806 | } else { | 806 | } else { |
| 807 | try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1); | 807 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); |
| 808 | module.failed_exports.putAssumeCapacityNoClobber( | 808 | module.failed_exports.putAssumeCapacityNoClobber( |
| 809 | exp, | 809 | exp, |
| 810 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: Exports other than '_start'", .{}), | 810 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: Exports other than '_start'", .{}), |
src/link/Elf.zig+15-15| ... | @@ -411,7 +411,7 @@ fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u16) u64 { | ... | @@ -411,7 +411,7 @@ fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u16) u64 { |
| 411 | 411 | ||
| 412 | /// TODO Improve this to use a table. | 412 | /// TODO Improve this to use a table. |
| 413 | fn makeString(self: *Elf, bytes: []const u8) !u32 { | 413 | fn makeString(self: *Elf, bytes: []const u8) !u32 { |
| 414 | try self.shstrtab.ensureCapacity(self.base.allocator, self.shstrtab.items.len + bytes.len + 1); | 414 | try self.shstrtab.ensureUnusedCapacity(self.base.allocator, bytes.len + 1); |
| 415 | const result = self.shstrtab.items.len; | 415 | const result = self.shstrtab.items.len; |
| 416 | self.shstrtab.appendSliceAssumeCapacity(bytes); | 416 | self.shstrtab.appendSliceAssumeCapacity(bytes); |
| 417 | self.shstrtab.appendAssumeCapacity(0); | 417 | self.shstrtab.appendAssumeCapacity(0); |
| ... | @@ -420,7 +420,7 @@ fn makeString(self: *Elf, bytes: []const u8) !u32 { | ... | @@ -420,7 +420,7 @@ fn makeString(self: *Elf, bytes: []const u8) !u32 { |
| 420 | 420 | ||
| 421 | /// TODO Improve this to use a table. | 421 | /// TODO Improve this to use a table. |
| 422 | fn makeDebugString(self: *Elf, bytes: []const u8) !u32 { | 422 | fn makeDebugString(self: *Elf, bytes: []const u8) !u32 { |
| 423 | try self.debug_strtab.ensureCapacity(self.base.allocator, self.debug_strtab.items.len + bytes.len + 1); | 423 | try self.debug_strtab.ensureUnusedCapacity(self.base.allocator, bytes.len + 1); |
| 424 | const result = self.debug_strtab.items.len; | 424 | const result = self.debug_strtab.items.len; |
| 425 | self.debug_strtab.appendSliceAssumeCapacity(bytes); | 425 | self.debug_strtab.appendSliceAssumeCapacity(bytes); |
| 426 | self.debug_strtab.appendAssumeCapacity(0); | 426 | self.debug_strtab.appendAssumeCapacity(0); |
| ... | @@ -856,7 +856,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { | ... | @@ -856,7 +856,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { |
| 856 | 856 | ||
| 857 | // We have a function to compute the upper bound size, because it's needed | 857 | // We have a function to compute the upper bound size, because it's needed |
| 858 | // for determining where to put the offset of the first `LinkBlock`. | 858 | // for determining where to put the offset of the first `LinkBlock`. |
| 859 | try di_buf.ensureCapacity(self.dbgInfoNeededHeaderBytes()); | 859 | try di_buf.ensureTotalCapacity(self.dbgInfoNeededHeaderBytes()); |
| 860 | 860 | ||
| 861 | // initial length - length of the .debug_info contribution for this compilation unit, | 861 | // initial length - length of the .debug_info contribution for this compilation unit, |
| 862 | // not including the initial length itself. | 862 | // not including the initial length itself. |
| ... | @@ -925,7 +925,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { | ... | @@ -925,7 +925,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { |
| 925 | 925 | ||
| 926 | // Enough for all the data without resizing. When support for more compilation units | 926 | // Enough for all the data without resizing. When support for more compilation units |
| 927 | // is added, the size of this section will become more variable. | 927 | // is added, the size of this section will become more variable. |
| 928 | try di_buf.ensureCapacity(100); | 928 | try di_buf.ensureTotalCapacity(100); |
| 929 | 929 | ||
| 930 | // initial length - length of the .debug_aranges contribution for this compilation unit, | 930 | // initial length - length of the .debug_aranges contribution for this compilation unit, |
| 931 | // not including the initial length itself. | 931 | // not including the initial length itself. |
| ... | @@ -1004,7 +1004,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { | ... | @@ -1004,7 +1004,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { |
| 1004 | // The size of this header is variable, depending on the number of directories, | 1004 | // The size of this header is variable, depending on the number of directories, |
| 1005 | // files, and padding. We have a function to compute the upper bound size, however, | 1005 | // files, and padding. We have a function to compute the upper bound size, however, |
| 1006 | // because it's needed for determining where to put the offset of the first `SrcFn`. | 1006 | // because it's needed for determining where to put the offset of the first `SrcFn`. |
| 1007 | try di_buf.ensureCapacity(self.dbgLineNeededHeaderBytes()); | 1007 | try di_buf.ensureTotalCapacity(self.dbgLineNeededHeaderBytes()); |
| 1008 | 1008 | ||
| 1009 | // initial length - length of the .debug_line contribution for this compilation unit, | 1009 | // initial length - length of the .debug_line contribution for this compilation unit, |
| 1010 | // not including the initial length itself. | 1010 | // not including the initial length itself. |
| ... | @@ -1639,7 +1639,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { | ... | @@ -1639,7 +1639,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1639 | // Shared libraries. | 1639 | // Shared libraries. |
| 1640 | if (is_exe_or_dyn_lib) { | 1640 | if (is_exe_or_dyn_lib) { |
| 1641 | const system_libs = self.base.options.system_libs.keys(); | 1641 | const system_libs = self.base.options.system_libs.keys(); |
| 1642 | try argv.ensureCapacity(argv.items.len + system_libs.len); | 1642 | try argv.ensureUnusedCapacity(system_libs.len); |
| 1643 | for (system_libs) |link_lib| { | 1643 | for (system_libs) |link_lib| { |
| 1644 | // By this time, we depend on these libs being dynamically linked libraries and not static libraries | 1644 | // By this time, we depend on these libs being dynamically linked libraries and not static libraries |
| 1645 | // (the check for that needs to be earlier), but they could be full paths to .so files, in which | 1645 | // (the check for that needs to be earlier), but they could be full paths to .so files, in which |
| ... | @@ -2113,8 +2113,8 @@ pub fn allocateDeclIndexes(self: *Elf, decl: *Module.Decl) !void { | ... | @@ -2113,8 +2113,8 @@ pub fn allocateDeclIndexes(self: *Elf, decl: *Module.Decl) !void { |
| 2113 | 2113 | ||
| 2114 | if (decl.link.elf.local_sym_index != 0) return; | 2114 | if (decl.link.elf.local_sym_index != 0) return; |
| 2115 | 2115 | ||
| 2116 | try self.local_symbols.ensureCapacity(self.base.allocator, self.local_symbols.items.len + 1); | 2116 | try self.local_symbols.ensureUnusedCapacity(self.base.allocator, 1); |
| 2117 | try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1); | 2117 | try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1); |
| 2118 | 2118 | ||
| 2119 | if (self.local_symbol_free_list.popOrNull()) |i| { | 2119 | if (self.local_symbol_free_list.popOrNull()) |i| { |
| 2120 | log.debug("reusing symbol index {d} for {s}", .{ i, decl.name }); | 2120 | log.debug("reusing symbol index {d} for {s}", .{ i, decl.name }); |
| ... | @@ -2316,7 +2316,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven | ... | @@ -2316,7 +2316,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2316 | defer deinitRelocs(self.base.allocator, &dbg_info_type_relocs); | 2316 | defer deinitRelocs(self.base.allocator, &dbg_info_type_relocs); |
| 2317 | 2317 | ||
| 2318 | // For functions we need to add a prologue to the debug line program. | 2318 | // For functions we need to add a prologue to the debug line program. |
| 2319 | try dbg_line_buffer.ensureCapacity(26); | 2319 | try dbg_line_buffer.ensureTotalCapacity(26); |
| 2320 | 2320 | ||
| 2321 | const decl = func.owner_decl; | 2321 | const decl = func.owner_decl; |
| 2322 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); | 2322 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); |
| ... | @@ -2351,7 +2351,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven | ... | @@ -2351,7 +2351,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2351 | 2351 | ||
| 2352 | // .debug_info subprogram | 2352 | // .debug_info subprogram |
| 2353 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; | 2353 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; |
| 2354 | try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 25 + decl_name_with_null.len); | 2354 | try dbg_info_buffer.ensureUnusedCapacity(25 + decl_name_with_null.len); |
| 2355 | 2355 | ||
| 2356 | const fn_ret_type = decl.ty.fnReturnType(); | 2356 | const fn_ret_type = decl.ty.fnReturnType(); |
| 2357 | const fn_ret_has_bits = fn_ret_type.hasCodeGenBits(); | 2357 | const fn_ret_has_bits = fn_ret_type.hasCodeGenBits(); |
| ... | @@ -2593,7 +2593,7 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo | ... | @@ -2593,7 +2593,7 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo |
| 2593 | }, | 2593 | }, |
| 2594 | .Int => { | 2594 | .Int => { |
| 2595 | const info = ty.intInfo(self.base.options.target); | 2595 | const info = ty.intInfo(self.base.options.target); |
| 2596 | try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12); | 2596 | try dbg_info_buffer.ensureUnusedCapacity(12); |
| 2597 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); | 2597 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); |
| 2598 | // DW.AT.encoding, DW.FORM.data1 | 2598 | // DW.AT.encoding, DW.FORM.data1 |
| 2599 | dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) { | 2599 | dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) { |
| ... | @@ -2607,7 +2607,7 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo | ... | @@ -2607,7 +2607,7 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo |
| 2607 | }, | 2607 | }, |
| 2608 | .Optional => { | 2608 | .Optional => { |
| 2609 | if (ty.isPtrLikeOptional()) { | 2609 | if (ty.isPtrLikeOptional()) { |
| 2610 | try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12); | 2610 | try dbg_info_buffer.ensureUnusedCapacity(12); |
| 2611 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); | 2611 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); |
| 2612 | // DW.AT.encoding, DW.FORM.data1 | 2612 | // DW.AT.encoding, DW.FORM.data1 |
| 2613 | dbg_info_buffer.appendAssumeCapacity(DW.ATE.address); | 2613 | dbg_info_buffer.appendAssumeCapacity(DW.ATE.address); |
| ... | @@ -2747,14 +2747,14 @@ pub fn updateDeclExports( | ... | @@ -2747,14 +2747,14 @@ pub fn updateDeclExports( |
| 2747 | const tracy = trace(@src()); | 2747 | const tracy = trace(@src()); |
| 2748 | defer tracy.end(); | 2748 | defer tracy.end(); |
| 2749 | 2749 | ||
| 2750 | try self.global_symbols.ensureCapacity(self.base.allocator, self.global_symbols.items.len + exports.len); | 2750 | try self.global_symbols.ensureUnusedCapacity(self.base.allocator, exports.len); |
| 2751 | if (decl.link.elf.local_sym_index == 0) return; | 2751 | if (decl.link.elf.local_sym_index == 0) return; |
| 2752 | const decl_sym = self.local_symbols.items[decl.link.elf.local_sym_index]; | 2752 | const decl_sym = self.local_symbols.items[decl.link.elf.local_sym_index]; |
| 2753 | 2753 | ||
| 2754 | for (exports) |exp| { | 2754 | for (exports) |exp| { |
| 2755 | if (exp.options.section) |section_name| { | 2755 | if (exp.options.section) |section_name| { |
| 2756 | if (!mem.eql(u8, section_name, ".text")) { | 2756 | if (!mem.eql(u8, section_name, ".text")) { |
| 2757 | try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1); | 2757 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); |
| 2758 | module.failed_exports.putAssumeCapacityNoClobber( | 2758 | module.failed_exports.putAssumeCapacityNoClobber( |
| 2759 | exp, | 2759 | exp, |
| 2760 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}), | 2760 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}), |
| ... | @@ -2772,7 +2772,7 @@ pub fn updateDeclExports( | ... | @@ -2772,7 +2772,7 @@ pub fn updateDeclExports( |
| 2772 | }, | 2772 | }, |
| 2773 | .Weak => elf.STB_WEAK, | 2773 | .Weak => elf.STB_WEAK, |
| 2774 | .LinkOnce => { | 2774 | .LinkOnce => { |
| 2775 | try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1); | 2775 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); |
| 2776 | module.failed_exports.putAssumeCapacityNoClobber( | 2776 | module.failed_exports.putAssumeCapacityNoClobber( |
| 2777 | exp, | 2777 | exp, |
| 2778 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: GlobalLinkage.LinkOnce", .{}), | 2778 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: GlobalLinkage.LinkOnce", .{}), |
src/link/MachO/CodeSignature.zig+1-1| ... | @@ -102,7 +102,7 @@ pub fn calcAdhocSignature( | ... | @@ -102,7 +102,7 @@ pub fn calcAdhocSignature( |
| 102 | var buffer = try allocator.alloc(u8, page_size); | 102 | var buffer = try allocator.alloc(u8, page_size); |
| 103 | defer allocator.free(buffer); | 103 | defer allocator.free(buffer); |
| 104 | 104 | ||
| 105 | try cdir.data.ensureCapacity(allocator, total_pages * hash_size + id.len + 1); | 105 | try cdir.data.ensureTotalCapacity(allocator, total_pages * hash_size + id.len + 1); |
| 106 | 106 | ||
| 107 | // 1. Save the identifier and update offsets | 107 | // 1. Save the identifier and update offsets |
| 108 | cdir.inner.identOffset = cdir.inner.length; | 108 | cdir.inner.identOffset = cdir.inner.length; |
src/link/MachO/DebugSymbols.zig+8-8| ... | @@ -353,7 +353,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt | ... | @@ -353,7 +353,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 353 | 353 | ||
| 354 | // We have a function to compute the upper bound size, because it's needed | 354 | // We have a function to compute the upper bound size, because it's needed |
| 355 | // for determining where to put the offset of the first `LinkBlock`. | 355 | // for determining where to put the offset of the first `LinkBlock`. |
| 356 | try di_buf.ensureCapacity(self.dbgInfoNeededHeaderBytes()); | 356 | try di_buf.ensureTotalCapacity(self.dbgInfoNeededHeaderBytes()); |
| 357 | 357 | ||
| 358 | // initial length - length of the .debug_info contribution for this compilation unit, | 358 | // initial length - length of the .debug_info contribution for this compilation unit, |
| 359 | // not including the initial length itself. | 359 | // not including the initial length itself. |
| ... | @@ -408,7 +408,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt | ... | @@ -408,7 +408,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 408 | 408 | ||
| 409 | // Enough for all the data without resizing. When support for more compilation units | 409 | // Enough for all the data without resizing. When support for more compilation units |
| 410 | // is added, the size of this section will become more variable. | 410 | // is added, the size of this section will become more variable. |
| 411 | try di_buf.ensureCapacity(100); | 411 | try di_buf.ensureTotalCapacity(100); |
| 412 | 412 | ||
| 413 | // initial length - length of the .debug_aranges contribution for this compilation unit, | 413 | // initial length - length of the .debug_aranges contribution for this compilation unit, |
| 414 | // not including the initial length itself. | 414 | // not including the initial length itself. |
| ... | @@ -479,7 +479,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt | ... | @@ -479,7 +479,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 479 | // The size of this header is variable, depending on the number of directories, | 479 | // The size of this header is variable, depending on the number of directories, |
| 480 | // files, and padding. We have a function to compute the upper bound size, however, | 480 | // files, and padding. We have a function to compute the upper bound size, however, |
| 481 | // because it's needed for determining where to put the offset of the first `SrcFn`. | 481 | // because it's needed for determining where to put the offset of the first `SrcFn`. |
| 482 | try di_buf.ensureCapacity(self.dbgLineNeededHeaderBytes(module)); | 482 | try di_buf.ensureTotalCapacity(self.dbgLineNeededHeaderBytes(module)); |
| 483 | 483 | ||
| 484 | // initial length - length of the .debug_line contribution for this compilation unit, | 484 | // initial length - length of the .debug_line contribution for this compilation unit, |
| 485 | // not including the initial length itself. | 485 | // not including the initial length itself. |
| ... | @@ -607,7 +607,7 @@ fn copySegmentCommand(self: *DebugSymbols, allocator: *Allocator, base_cmd: Segm | ... | @@ -607,7 +607,7 @@ fn copySegmentCommand(self: *DebugSymbols, allocator: *Allocator, base_cmd: Segm |
| 607 | }; | 607 | }; |
| 608 | mem.copy(u8, &cmd.inner.segname, &base_cmd.inner.segname); | 608 | mem.copy(u8, &cmd.inner.segname, &base_cmd.inner.segname); |
| 609 | 609 | ||
| 610 | try cmd.sections.ensureCapacity(allocator, cmd.inner.nsects); | 610 | try cmd.sections.ensureTotalCapacity(allocator, cmd.inner.nsects); |
| 611 | for (base_cmd.sections.items) |base_sect, i| { | 611 | for (base_cmd.sections.items) |base_sect, i| { |
| 612 | var sect = macho.section_64{ | 612 | var sect = macho.section_64{ |
| 613 | .sectname = undefined, | 613 | .sectname = undefined, |
| ... | @@ -855,7 +855,7 @@ pub fn initDeclDebugBuffers( | ... | @@ -855,7 +855,7 @@ pub fn initDeclDebugBuffers( |
| 855 | switch (decl.ty.zigTypeTag()) { | 855 | switch (decl.ty.zigTypeTag()) { |
| 856 | .Fn => { | 856 | .Fn => { |
| 857 | // For functions we need to add a prologue to the debug line program. | 857 | // For functions we need to add a prologue to the debug line program. |
| 858 | try dbg_line_buffer.ensureCapacity(26); | 858 | try dbg_line_buffer.ensureTotalCapacity(26); |
| 859 | 859 | ||
| 860 | const func = decl.val.castTag(.function).?.data; | 860 | const func = decl.val.castTag(.function).?.data; |
| 861 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); | 861 | const line_off = @intCast(u28, decl.src_line + func.lbrace_line); |
| ... | @@ -889,7 +889,7 @@ pub fn initDeclDebugBuffers( | ... | @@ -889,7 +889,7 @@ pub fn initDeclDebugBuffers( |
| 889 | 889 | ||
| 890 | // .debug_info subprogram | 890 | // .debug_info subprogram |
| 891 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; | 891 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; |
| 892 | try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 27 + decl_name_with_null.len); | 892 | try dbg_info_buffer.ensureUnusedCapacity(27 + decl_name_with_null.len); |
| 893 | 893 | ||
| 894 | const fn_ret_type = decl.ty.fnReturnType(); | 894 | const fn_ret_type = decl.ty.fnReturnType(); |
| 895 | const fn_ret_has_bits = fn_ret_type.hasCodeGenBits(); | 895 | const fn_ret_has_bits = fn_ret_type.hasCodeGenBits(); |
| ... | @@ -1124,7 +1124,7 @@ fn addDbgInfoType( | ... | @@ -1124,7 +1124,7 @@ fn addDbgInfoType( |
| 1124 | }, | 1124 | }, |
| 1125 | .Int => { | 1125 | .Int => { |
| 1126 | const info = ty.intInfo(target); | 1126 | const info = ty.intInfo(target); |
| 1127 | try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12); | 1127 | try dbg_info_buffer.ensureUnusedCapacity(12); |
| 1128 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); | 1128 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); |
| 1129 | // DW.AT.encoding, DW.FORM.data1 | 1129 | // DW.AT.encoding, DW.FORM.data1 |
| 1130 | dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) { | 1130 | dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) { |
| ... | @@ -1261,7 +1261,7 @@ fn getDebugLineProgramEnd(self: DebugSymbols) u32 { | ... | @@ -1261,7 +1261,7 @@ fn getDebugLineProgramEnd(self: DebugSymbols) u32 { |
| 1261 | 1261 | ||
| 1262 | /// TODO Improve this to use a table. | 1262 | /// TODO Improve this to use a table. |
| 1263 | fn makeDebugString(self: *DebugSymbols, allocator: *Allocator, bytes: []const u8) !u32 { | 1263 | fn makeDebugString(self: *DebugSymbols, allocator: *Allocator, bytes: []const u8) !u32 { |
| 1264 | try self.debug_string_table.ensureCapacity(allocator, self.debug_string_table.items.len + bytes.len + 1); | 1264 | try self.debug_string_table.ensureUnusedCapacity(allocator, bytes.len + 1); |
| 1265 | const result = self.debug_string_table.items.len; | 1265 | const result = self.debug_string_table.items.len; |
| 1266 | self.debug_string_table.appendSliceAssumeCapacity(bytes); | 1266 | self.debug_string_table.appendSliceAssumeCapacity(bytes); |
| 1267 | self.debug_string_table.appendAssumeCapacity(0); | 1267 | self.debug_string_table.appendAssumeCapacity(0); |
src/link/MachO/Dylib.zig+1-1| ... | @@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void { | ... | @@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void { |
| 180 | fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void { | 180 | fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void { |
| 181 | const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0; | 181 | const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0; |
| 182 | 182 | ||
| 183 | try self.load_commands.ensureCapacity(allocator, self.header.?.ncmds); | 183 | try self.load_commands.ensureTotalCapacity(allocator, self.header.?.ncmds); |
| 184 | 184 | ||
| 185 | var i: u16 = 0; | 185 | var i: u16 = 0; |
| 186 | while (i < self.header.?.ncmds) : (i += 1) { | 186 | while (i < self.header.?.ncmds) : (i += 1) { |
src/link/MachO/Object.zig+1-1| ... | @@ -261,7 +261,7 @@ pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) ! | ... | @@ -261,7 +261,7 @@ pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) ! |
| 261 | const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition. | 261 | const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition. |
| 262 | const offset = self.file_offset orelse 0; | 262 | const offset = self.file_offset orelse 0; |
| 263 | 263 | ||
| 264 | try self.load_commands.ensureCapacity(allocator, header.ncmds); | 264 | try self.load_commands.ensureTotalCapacity(allocator, header.ncmds); |
| 265 | 265 | ||
| 266 | var i: u16 = 0; | 266 | var i: u16 = 0; |
| 267 | while (i < header.ncmds) : (i += 1) { | 267 | while (i < header.ncmds) : (i += 1) { |
src/link/MachO/Trie.zig+1-1| ... | @@ -326,7 +326,7 @@ pub fn finalize(self: *Trie, allocator: *Allocator) !void { | ... | @@ -326,7 +326,7 @@ pub fn finalize(self: *Trie, allocator: *Allocator) !void { |
| 326 | if (!self.trie_dirty) return; | 326 | if (!self.trie_dirty) return; |
| 327 | 327 | ||
| 328 | self.ordered_nodes.shrinkRetainingCapacity(0); | 328 | self.ordered_nodes.shrinkRetainingCapacity(0); |
| 329 | try self.ordered_nodes.ensureCapacity(allocator, self.node_count); | 329 | try self.ordered_nodes.ensureTotalCapacity(allocator, self.node_count); |
| 330 | 330 | ||
| 331 | var fifo = std.fifo.LinearFifo(*Node, .Dynamic).init(allocator); | 331 | var fifo = std.fifo.LinearFifo(*Node, .Dynamic).init(allocator); |
| 332 | defer fifo.deinit(); | 332 | defer fifo.deinit(); |
src/link/MachO/commands.zig+1-1| ... | @@ -223,7 +223,7 @@ pub const SegmentCommand = struct { | ... | @@ -223,7 +223,7 @@ pub const SegmentCommand = struct { |
| 223 | var segment = SegmentCommand{ | 223 | var segment = SegmentCommand{ |
| 224 | .inner = inner, | 224 | .inner = inner, |
| 225 | }; | 225 | }; |
| 226 | try segment.sections.ensureCapacity(alloc, inner.nsects); | 226 | try segment.sections.ensureTotalCapacity(alloc, inner.nsects); |
| 227 | 227 | ||
| 228 | var i: usize = 0; | 228 | var i: usize = 0; |
| 229 | while (i < inner.nsects) : (i += 1) { | 229 | while (i < inner.nsects) : (i += 1) { |
src/link/Wasm.zig+2-2| ... | @@ -172,8 +172,8 @@ pub fn deinit(self: *Wasm) void { | ... | @@ -172,8 +172,8 @@ pub fn deinit(self: *Wasm) void { |
| 172 | pub fn allocateDeclIndexes(self: *Wasm, decl: *Module.Decl) !void { | 172 | pub fn allocateDeclIndexes(self: *Wasm, decl: *Module.Decl) !void { |
| 173 | if (decl.link.wasm.init) return; | 173 | if (decl.link.wasm.init) return; |
| 174 | 174 | ||
| 175 | try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1); | 175 | try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1); |
| 176 | try self.symbols.ensureCapacity(self.base.allocator, self.symbols.items.len + 1); | 176 | try self.symbols.ensureUnusedCapacity(self.base.allocator, 1); |
| 177 | 177 | ||
| 178 | const block = &decl.link.wasm; | 178 | const block = &decl.link.wasm; |
| 179 | block.init = true; | 179 | block.init = true; |
src/main.zig+6-6| ... | @@ -1704,22 +1704,22 @@ fn buildOutputType( | ... | @@ -1704,22 +1704,22 @@ fn buildOutputType( |
| 1704 | } else true; | 1704 | } else true; |
| 1705 | if (!should_get_sdk_path) break :outer false; | 1705 | if (!should_get_sdk_path) break :outer false; |
| 1706 | if (try std.zig.system.darwin.getSDKPath(arena, target_info.target)) |sdk_path| { | 1706 | if (try std.zig.system.darwin.getSDKPath(arena, target_info.target)) |sdk_path| { |
| 1707 | try clang_argv.ensureCapacity(clang_argv.items.len + 2); | 1707 | try clang_argv.ensureUnusedCapacity(2); |
| 1708 | clang_argv.appendAssumeCapacity("-isysroot"); | 1708 | clang_argv.appendAssumeCapacity("-isysroot"); |
| 1709 | clang_argv.appendAssumeCapacity(sdk_path); | 1709 | clang_argv.appendAssumeCapacity(sdk_path); |
| 1710 | break :outer true; | 1710 | break :outer true; |
| 1711 | } else break :outer false; | 1711 | } else break :outer false; |
| 1712 | } else false; | 1712 | } else false; |
| 1713 | 1713 | ||
| 1714 | try clang_argv.ensureCapacity(clang_argv.items.len + paths.include_dirs.items.len * 2); | 1714 | try clang_argv.ensureUnusedCapacity(paths.include_dirs.items.len * 2); |
| 1715 | const isystem_flag = if (has_sysroot) "-iwithsysroot" else "-isystem"; | 1715 | const isystem_flag = if (has_sysroot) "-iwithsysroot" else "-isystem"; |
| 1716 | for (paths.include_dirs.items) |include_dir| { | 1716 | for (paths.include_dirs.items) |include_dir| { |
| 1717 | clang_argv.appendAssumeCapacity(isystem_flag); | 1717 | clang_argv.appendAssumeCapacity(isystem_flag); |
| 1718 | clang_argv.appendAssumeCapacity(include_dir); | 1718 | clang_argv.appendAssumeCapacity(include_dir); |
| 1719 | } | 1719 | } |
| 1720 | 1720 | ||
| 1721 | try clang_argv.ensureCapacity(clang_argv.items.len + paths.framework_dirs.items.len * 2); | 1721 | try clang_argv.ensureUnusedCapacity(paths.framework_dirs.items.len * 2); |
| 1722 | try framework_dirs.ensureCapacity(framework_dirs.items.len + paths.framework_dirs.items.len); | 1722 | try framework_dirs.ensureUnusedCapacity(paths.framework_dirs.items.len); |
| 1723 | const iframework_flag = if (has_sysroot) "-iframeworkwithsysroot" else "-iframework"; | 1723 | const iframework_flag = if (has_sysroot) "-iframeworkwithsysroot" else "-iframework"; |
| 1724 | for (paths.framework_dirs.items) |framework_dir| { | 1724 | for (paths.framework_dirs.items) |framework_dir| { |
| 1725 | clang_argv.appendAssumeCapacity(iframework_flag); | 1725 | clang_argv.appendAssumeCapacity(iframework_flag); |
| ... | @@ -2783,7 +2783,7 @@ pub fn cmdInit( | ... | @@ -2783,7 +2783,7 @@ pub fn cmdInit( |
| 2783 | fatal("unable to read template file 'build.zig': {s}", .{@errorName(err)}); | 2783 | fatal("unable to read template file 'build.zig': {s}", .{@errorName(err)}); |
| 2784 | }; | 2784 | }; |
| 2785 | var modified_build_zig_contents = std.ArrayList(u8).init(arena); | 2785 | var modified_build_zig_contents = std.ArrayList(u8).init(arena); |
| 2786 | try modified_build_zig_contents.ensureCapacity(build_zig_contents.len); | 2786 | try modified_build_zig_contents.ensureTotalCapacity(build_zig_contents.len); |
| 2787 | for (build_zig_contents) |c| { | 2787 | for (build_zig_contents) |c| { |
| 2788 | if (c == '$') { | 2788 | if (c == '$') { |
| 2789 | try modified_build_zig_contents.appendSlice(cwd_basename); | 2789 | try modified_build_zig_contents.appendSlice(cwd_basename); |
| ... | @@ -3464,7 +3464,7 @@ fn fmtPathFile( | ... | @@ -3464,7 +3464,7 @@ fn fmtPathFile( |
| 3464 | 3464 | ||
| 3465 | // As a heuristic, we make enough capacity for the same as the input source. | 3465 | // As a heuristic, we make enough capacity for the same as the input source. |
| 3466 | fmt.out_buffer.shrinkRetainingCapacity(0); | 3466 | fmt.out_buffer.shrinkRetainingCapacity(0); |
| 3467 | try fmt.out_buffer.ensureCapacity(source_code.len); | 3467 | try fmt.out_buffer.ensureTotalCapacity(source_code.len); |
| 3468 | 3468 | ||
| 3469 | try tree.renderToArrayList(&fmt.out_buffer); | 3469 | try tree.renderToArrayList(&fmt.out_buffer); |
| 3470 | if (mem.eql(u8, fmt.out_buffer.items, source_code)) | 3470 | if (mem.eql(u8, fmt.out_buffer.items, source_code)) |
src/mingw.zig+1-1| ... | @@ -312,7 +312,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { | ... | @@ -312,7 +312,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 312 | if (try man.hit()) { | 312 | if (try man.hit()) { |
| 313 | const digest = man.final(); | 313 | const digest = man.final(); |
| 314 | 314 | ||
| 315 | try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1); | 315 | try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1); |
| 316 | comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{ | 316 | comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{ |
| 317 | .full_object_path = try comp.global_cache_directory.join(comp.gpa, &[_][]const u8{ | 317 | .full_object_path = try comp.global_cache_directory.join(comp.gpa, &[_][]const u8{ |
| 318 | "o", &digest, final_lib_basename, | 318 | "o", &digest, final_lib_basename, |
src/musl.zig+2-2| ... | @@ -112,7 +112,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -112,7 +112,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 112 | var source_table = std.StringArrayHashMap(Ext).init(comp.gpa); | 112 | var source_table = std.StringArrayHashMap(Ext).init(comp.gpa); |
| 113 | defer source_table.deinit(); | 113 | defer source_table.deinit(); |
| 114 | 114 | ||
| 115 | try source_table.ensureCapacity(compat_time32_files.len + src_files.len); | 115 | try source_table.ensureTotalCapacity(compat_time32_files.len + src_files.len); |
| 116 | 116 | ||
| 117 | for (src_files) |src_file| { | 117 | for (src_files) |src_file| { |
| 118 | try addSrcFile(arena, &source_table, src_file); | 118 | try addSrcFile(arena, &source_table, src_file); |
| ... | @@ -231,7 +231,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -231,7 +231,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 231 | 231 | ||
| 232 | try sub_compilation.updateSubCompilation(); | 232 | try sub_compilation.updateSubCompilation(); |
| 233 | 233 | ||
| 234 | try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1); | 234 | try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1); |
| 235 | 235 | ||
| 236 | const basename = try comp.gpa.dupe(u8, "libc.so"); | 236 | const basename = try comp.gpa.dupe(u8, "libc.so"); |
| 237 | errdefer comp.gpa.free(basename); | 237 | errdefer comp.gpa.free(basename); |
src/translate_c.zig+1-1| ... | @@ -4882,7 +4882,7 @@ fn finishTransFnProto( | ... | @@ -4882,7 +4882,7 @@ fn finishTransFnProto( |
| 4882 | var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa); | 4882 | var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa); |
| 4883 | defer fn_params.deinit(); | 4883 | defer fn_params.deinit(); |
| 4884 | const param_count: usize = if (fn_proto_ty != null) fn_proto_ty.?.getNumParams() else 0; | 4884 | const param_count: usize = if (fn_proto_ty != null) fn_proto_ty.?.getNumParams() else 0; |
| 4885 | try fn_params.ensureCapacity(param_count); | 4885 | try fn_params.ensureTotalCapacity(param_count); |
| 4886 | 4886 | ||
| 4887 | var i: usize = 0; | 4887 | var i: usize = 0; |
| 4888 | while (i < param_count) : (i += 1) { | 4888 | while (i < param_count) : (i += 1) { |
src/translate_c/ast.zig+5-5| ... | @@ -728,13 +728,13 @@ pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.Ast { | ... | @@ -728,13 +728,13 @@ pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.Ast { |
| 728 | 728 | ||
| 729 | // Estimate that each top level node has 10 child nodes. | 729 | // Estimate that each top level node has 10 child nodes. |
| 730 | const estimated_node_count = nodes.len * 10; | 730 | const estimated_node_count = nodes.len * 10; |
| 731 | try ctx.nodes.ensureCapacity(gpa, estimated_node_count); | 731 | try ctx.nodes.ensureTotalCapacity(gpa, estimated_node_count); |
| 732 | // Estimate that each each node has 2 tokens. | 732 | // Estimate that each each node has 2 tokens. |
| 733 | const estimated_tokens_count = estimated_node_count * 2; | 733 | const estimated_tokens_count = estimated_node_count * 2; |
| 734 | try ctx.tokens.ensureCapacity(gpa, estimated_tokens_count); | 734 | try ctx.tokens.ensureTotalCapacity(gpa, estimated_tokens_count); |
| 735 | // Estimate that each each token is 3 bytes long. | 735 | // Estimate that each each token is 3 bytes long. |
| 736 | const estimated_buf_len = estimated_tokens_count * 3; | 736 | const estimated_buf_len = estimated_tokens_count * 3; |
| 737 | try ctx.buf.ensureCapacity(estimated_buf_len); | 737 | try ctx.buf.ensureTotalCapacity(estimated_buf_len); |
| 738 | 738 | ||
| 739 | ctx.nodes.appendAssumeCapacity(.{ | 739 | ctx.nodes.appendAssumeCapacity(.{ |
| 740 | .tag = .root, | 740 | .tag = .root, |
| ... | @@ -839,7 +839,7 @@ const Context = struct { | ... | @@ -839,7 +839,7 @@ const Context = struct { |
| 839 | 839 | ||
| 840 | fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex { | 840 | fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex { |
| 841 | const fields = std.meta.fields(@TypeOf(extra)); | 841 | const fields = std.meta.fields(@TypeOf(extra)); |
| 842 | try c.extra_data.ensureCapacity(c.gpa, c.extra_data.items.len + fields.len); | 842 | try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len); |
| 843 | const result = @intCast(u32, c.extra_data.items.len); | 843 | const result = @intCast(u32, c.extra_data.items.len); |
| 844 | inline for (fields) |field| { | 844 | inline for (fields) |field| { |
| 845 | comptime std.debug.assert(field.field_type == NodeIndex); | 845 | comptime std.debug.assert(field.field_type == NodeIndex); |
| ... | @@ -2797,7 +2797,7 @@ fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.Ar | ... | @@ -2797,7 +2797,7 @@ fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.Ar |
| 2797 | _ = try c.addToken(.l_paren, "("); | 2797 | _ = try c.addToken(.l_paren, "("); |
| 2798 | var rendered = std.ArrayList(NodeIndex).init(c.gpa); | 2798 | var rendered = std.ArrayList(NodeIndex).init(c.gpa); |
| 2799 | errdefer rendered.deinit(); | 2799 | errdefer rendered.deinit(); |
| 2800 | try rendered.ensureCapacity(std.math.max(params.len, 1)); | 2800 | try rendered.ensureTotalCapacity(std.math.max(params.len, 1)); |
| 2801 | 2801 | ||
| 2802 | for (params) |param, i| { | 2802 | for (params) |param, i| { |
| 2803 | if (i != 0) _ = try c.addToken(.comma, ","); | 2803 | if (i != 0) _ = try c.addToken(.comma, ","); |