authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2021-09-16 18:22:04-07:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-09-19 13:52:56+02:00
log59f5053beda7087a73983835e9f7e00dc3143d59
treed43b3a97472532c699d8ee9d741ae97766d3e209
parentfeeb25908bebd5d09cf05128fad7d7c1a8a803a1

Update all ensureCapacity calls to the relevant non-deprecated version


38 files changed, 134 insertions(+), 137 deletions(-)

lib/std/array_hash_map.zig+10-10
......@@ -90,7 +90,7 @@ pub fn ArrayHashMap(
9090 /// Modifying the key is allowed only if it does not change the hash.
9191 /// Modifying the value is allowed.
9292 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
93 /// unless `ensureCapacity` was previously used.
93 /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
9494 pub const Entry = Unmanaged.Entry;
9595
9696 /// A KV pair which has been copied out of the backing store
......@@ -110,7 +110,7 @@ pub fn ArrayHashMap(
110110 /// Modifying the key is allowed only if it does not change the hash.
111111 /// Modifying the value is allowed.
112112 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
113 /// unless `ensureCapacity` was previously used.
113 /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
114114 pub const GetOrPutResult = Unmanaged.GetOrPutResult;
115115
116116 /// An Iterator over Entry pointers.
......@@ -478,7 +478,7 @@ pub fn ArrayHashMapUnmanaged(
478478 /// Modifying the key is allowed only if it does not change the hash.
479479 /// Modifying the value is allowed.
480480 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
481 /// unless `ensureCapacity` was previously used.
481 /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
482482 pub const Entry = struct {
483483 key_ptr: *K,
484484 value_ptr: *V,
......@@ -509,7 +509,7 @@ pub fn ArrayHashMapUnmanaged(
509509 /// Modifying the key is allowed only if it does not change the hash.
510510 /// Modifying the value is allowed.
511511 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
512 /// unless `ensureCapacity` was previously used.
512 /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
513513 pub const GetOrPutResult = struct {
514514 key_ptr: *K,
515515 value_ptr: *V,
......@@ -759,20 +759,20 @@ pub fn ArrayHashMapUnmanaged(
759759 }
760760 pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void {
761761 if (new_capacity <= linear_scan_max) {
762 try self.entries.ensureCapacity(allocator, new_capacity);
762 try self.entries.ensureTotalCapacity(allocator, new_capacity);
763763 return;
764764 }
765765
766766 if (self.index_header) |header| {
767767 if (new_capacity <= header.capacity()) {
768 try self.entries.ensureCapacity(allocator, new_capacity);
768 try self.entries.ensureTotalCapacity(allocator, new_capacity);
769769 return;
770770 }
771771 }
772772
773773 const new_bit_index = try IndexHeader.findBitIndex(new_capacity);
774774 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);
776776
777777 if (self.index_header) |old_header| old_header.free(allocator);
778778 self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header);
......@@ -1441,7 +1441,7 @@ pub fn ArrayHashMapUnmanaged(
14411441 unreachable;
14421442 }
14431443
1444 /// Must ensureCapacity before calling this.
1444 /// Must `ensureTotalCapacity`/`ensureUnusedCapacity` before calling this.
14451445 fn getOrPutInternal(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type) GetOrPutResult {
14461446 const slice = self.entries.slice();
14471447 const hashes_array = if (store_hash) slice.items(.hash) else {};
......@@ -1485,7 +1485,7 @@ pub fn ArrayHashMapUnmanaged(
14851485 }
14861486
14871487 // This pointer survives the following append because we call
1488 // entries.ensureCapacity before getOrPutInternal.
1488 // entries.ensureTotalCapacity before getOrPutInternal.
14891489 const hash_match = if (store_hash) h == hashes_array[slot_data.entry_index] else true;
14901490 if (hash_match and checkedEql(ctx, key, keys_array[slot_data.entry_index])) {
14911491 return .{
......@@ -1946,7 +1946,7 @@ test "iterator hash map" {
19461946 var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
19471947 defer reset_map.deinit();
19481948
1949 // test ensureCapacity with a 0 parameter
1949 // test ensureTotalCapacity with a 0 parameter
19501950 try reset_map.ensureTotalCapacity(0);
19511951
19521952 try reset_map.putNoClobber(0, 11);
lib/std/child_process.zig+5-5
......@@ -195,7 +195,7 @@ pub const ChildProcess = struct {
195195 };
196196
197197 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
199199 // effect on small reads because once the reads start to get larger the amount
200200 // of space an ArrayList will allocate grows exponentially.
201201 const bump_amt = 512;
......@@ -215,7 +215,7 @@ pub const ChildProcess = struct {
215215 if (poll_fds[0].revents & os.POLL.IN != 0) {
216216 // stdout is ready.
217217 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);
219219 const buf = stdout.unusedCapacitySlice();
220220 if (buf.len == 0) return error.StdoutStreamTooLong;
221221 const nread = try os.read(poll_fds[0].fd, buf);
......@@ -230,7 +230,7 @@ pub const ChildProcess = struct {
230230 if (poll_fds[1].revents & os.POLL.IN != 0) {
231231 // stderr is ready.
232232 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);
234234 const buf = stderr.unusedCapacitySlice();
235235 if (buf.len == 0) return error.StderrStreamTooLong;
236236 const nread = try os.read(poll_fds[1].fd, buf);
......@@ -276,7 +276,7 @@ pub const ChildProcess = struct {
276276
277277 // Windows Async IO requires an initial call to ReadFile before waiting on the handle
278278 for ([_]u1{ 0, 1 }) |i| {
279 try outs[i].ensureCapacity(bump_amt);
279 try outs[i].ensureTotalCapacity(bump_amt);
280280 const buf = outs[i].unusedCapacitySlice();
281281 _ = windows.kernel32.ReadFile(handles[i], buf.ptr, math.cast(u32, buf.len) catch maxInt(u32), null, &overlapped[i]);
282282 wait_objects[wait_object_count] = handles[i];
......@@ -318,7 +318,7 @@ pub const ChildProcess = struct {
318318
319319 outs[i].items.len += read_bytes;
320320 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);
322322 const buf = outs[i].unusedCapacitySlice();
323323 if (buf.len == 0) return if (i == 0) error.StdoutStreamTooLong else error.StderrStreamTooLong;
324324 _ = 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 {
277277 if (self.sections.items.len == self.coff_header.number_of_sections)
278278 return;
279279
280 try self.sections.ensureCapacity(self.coff_header.number_of_sections);
280 try self.sections.ensureTotalCapacity(self.coff_header.number_of_sections);
281281
282282 const in = self.in_file.reader();
283283
lib/std/hash_map.zig+9-9
......@@ -1568,11 +1568,11 @@ test "std.hash_map basic usage" {
15681568 try expectEqual(total, sum);
15691569}
15701570
1571test "std.hash_map ensureCapacity" {
1571test "std.hash_map ensureTotalCapacity" {
15721572 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
15731573 defer map.deinit();
15741574
1575 try map.ensureCapacity(20);
1575 try map.ensureTotalCapacity(20);
15761576 const initial_capacity = map.capacity();
15771577 try testing.expect(initial_capacity >= 20);
15781578 var i: i32 = 0;
......@@ -1583,13 +1583,13 @@ test "std.hash_map ensureCapacity" {
15831583 try testing.expect(initial_capacity == map.capacity());
15841584}
15851585
1586test "std.hash_map ensureCapacity with tombstones" {
1586test "std.hash_map ensureUnusedCapacity with tombstones" {
15871587 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
15881588 defer map.deinit();
15891589
15901590 var i: i32 = 0;
15911591 while (i < 100) : (i += 1) {
1592 try map.ensureCapacity(@intCast(u32, map.count() + 1));
1592 try map.ensureUnusedCapacity(1);
15931593 map.putAssumeCapacity(i, i);
15941594 // Remove to create tombstones that still count as load in the hashmap.
15951595 _ = map.remove(i);
......@@ -1669,7 +1669,7 @@ test "std.hash_map clone" {
16691669 try expectEqual(b.get(3).?, 3);
16701670}
16711671
1672test "std.hash_map ensureCapacity with existing elements" {
1672test "std.hash_map ensureTotalCapacity with existing elements" {
16731673 var map = AutoHashMap(u32, u32).init(std.testing.allocator);
16741674 defer map.deinit();
16751675
......@@ -1677,16 +1677,16 @@ test "std.hash_map ensureCapacity with existing elements" {
16771677 try expectEqual(map.count(), 1);
16781678 try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
16791679
1680 try map.ensureCapacity(65);
1680 try map.ensureTotalCapacity(65);
16811681 try expectEqual(map.count(), 1);
16821682 try expectEqual(map.capacity(), 128);
16831683}
16841684
1685test "std.hash_map ensureCapacity satisfies max load factor" {
1685test "std.hash_map ensureTotalCapacity satisfies max load factor" {
16861686 var map = AutoHashMap(u32, u32).init(std.testing.allocator);
16871687 defer map.deinit();
16881688
1689 try map.ensureCapacity(127);
1689 try map.ensureTotalCapacity(127);
16901690 try expectEqual(map.capacity(), 256);
16911691}
16921692
......@@ -1870,7 +1870,7 @@ test "std.hash_map putAssumeCapacity" {
18701870 var map = AutoHashMap(u32, u32).init(std.testing.allocator);
18711871 defer map.deinit();
18721872
1873 try map.ensureCapacity(20);
1873 try map.ensureTotalCapacity(20);
18741874 var i: u32 = 0;
18751875 while (i < 20) : (i += 1) {
18761876 map.putAssumeCapacityNoClobber(i, i);
lib/std/heap/general_purpose_allocator.zig+1-4
......@@ -746,10 +746,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
746746
747747 const new_aligned_size = math.max(len, ptr_align);
748748 if (new_aligned_size > largest_bucket_object_size) {
749 try self.large_allocations.ensureCapacity(
750 self.backing_allocator,
751 self.large_allocations.count() + 1,
752 );
749 try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1);
753750
754751 const slice = try self.backing_allocator.allocFn(self.backing_allocator, len, ptr_align, len_align, ret_addr);
755752
lib/std/io/reader.zig+2-2
......@@ -61,7 +61,7 @@ pub fn Reader(
6161 array_list: *std.ArrayListAligned(u8, alignment),
6262 max_append_size: usize,
6363 ) !void {
64 try array_list.ensureCapacity(math.min(max_append_size, 4096));
64 try array_list.ensureTotalCapacity(math.min(max_append_size, 4096));
6565 const original_len = array_list.items.len;
6666 var start_index: usize = original_len;
6767 while (true) {
......@@ -81,7 +81,7 @@ pub fn Reader(
8181 }
8282
8383 // 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);
8585 }
8686 }
8787
lib/std/json.zig+1-1
......@@ -1838,7 +1838,7 @@ fn parseInternal(
18381838 else => {},
18391839 }
18401840
1841 try arraylist.ensureCapacity(arraylist.items.len + 1);
1841 try arraylist.ensureUnusedCapacity(1);
18421842 const v = try parseInternal(ptrInfo.child, tok, tokens, options);
18431843 arraylist.appendAssumeCapacity(v);
18441844 }
lib/std/multi_array_list.zig+2-2
......@@ -189,7 +189,7 @@ pub fn MultiArrayList(comptime S: type) type {
189189 /// sets the given index to the specified element. May reallocate
190190 /// and invalidate iterators.
191191 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);
193193 self.insertAssumeCapacity(index, elem);
194194 }
195195
......@@ -376,7 +376,7 @@ pub fn MultiArrayList(comptime S: type) type {
376376 pub fn clone(self: Self, gpa: *Allocator) !Self {
377377 var result = Self{};
378378 errdefer result.deinit(gpa);
379 try result.ensureCapacity(gpa, self.len);
379 try result.ensureTotalCapacity(gpa, self.len);
380380 result.len = self.len;
381381 const self_slice = self.slice();
382382 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
668668 var result = std.ArrayList(u16).init(allocator);
669669 errdefer result.deinit();
670670 // optimistically guess that it will not require surrogate pairs
671 try result.ensureCapacity(utf8.len + 1);
671 try result.ensureTotalCapacity(utf8.len + 1);
672672
673673 const view = try Utf8View.init(utf8);
674674 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 {
1717
1818 // Empirically, the zig std lib has an 8:1 ratio of source bytes to token count.
1919 const estimated_token_count = source.len / 8;
20 try tokens.ensureCapacity(gpa, estimated_token_count);
20 try tokens.ensureTotalCapacity(gpa, estimated_token_count);
2121
2222 var tokenizer = std.zig.Tokenizer.init(source);
2323 while (true) {
......@@ -48,7 +48,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast {
4848 // Empirically, Zig source code has a 2:1 ratio of tokens to AST nodes.
4949 // Make sure at least 1 so we can use appendAssumeCapacity on the root node below.
5050 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);
5252
5353 // Root node must be index 0.
5454 // Root <- skip ContainerMembers eof
......@@ -138,7 +138,7 @@ const Parser = struct {
138138
139139 fn addExtra(p: *Parser, extra: anytype) Allocator.Error!Node.Index {
140140 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);
142142 const result = @intCast(u32, p.extra_data.items.len);
143143 inline for (fields) |field| {
144144 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
2929 const slice = bytes[1..];
3030
3131 const prev_len = buf.items.len;
32 try buf.ensureCapacity(prev_len + slice.len - 1);
32 try buf.ensureUnusedCapacity(slice.len - 1);
3333 errdefer buf.shrinkRetainingCapacity(prev_len);
3434
3535 const State = enum {
src/AstGen.zig+2-2
......@@ -3515,7 +3515,7 @@ fn structDeclInner(
35153515 defer wip_decls.deinit(gpa);
35163516
35173517 // We don't know which members are fields until we iterate, so cannot do
3518 // an accurate ensureCapacity yet.
3518 // an accurate ensureTotalCapacity yet.
35193519 var fields_data = ArrayListUnmanaged(u32){};
35203520 defer fields_data.deinit(gpa);
35213521
......@@ -3791,7 +3791,7 @@ fn unionDeclInner(
37913791 defer wip_decls.deinit(gpa);
37923792
37933793 // We don't know which members are fields until we iterate, so cannot do
3794 // an accurate ensureCapacity yet.
3794 // an accurate ensureTotalCapacity yet.
37953795 var fields_data = ArrayListUnmanaged(u32){};
37963796 defer fields_data.deinit(gpa);
37973797
src/Cache.zig+1-1
......@@ -210,7 +210,7 @@ pub const Manifest = struct {
210210 pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize {
211211 assert(self.manifest_file == null);
212212
213 try self.files.ensureCapacity(self.cache.gpa, self.files.items.len + 1);
213 try self.files.ensureUnusedCapacity(self.cache.gpa, 1);
214214 const resolved_path = try fs.path.resolve(self.cache.gpa, &[_][]const u8{file_path});
215215
216216 const idx = self.files.items.len;
src/Compilation.zig+9-9
......@@ -1097,7 +1097,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
10971097
10981098 if (feature.llvm_name) |llvm_name| {
10991099 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);
11011101 buf.appendAssumeCapacity(plus_or_minus);
11021102 buf.appendSliceAssumeCapacity(llvm_name);
11031103 buf.appendSliceAssumeCapacity(",");
......@@ -1347,7 +1347,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
13471347
13481348 var system_libs: std.StringArrayHashMapUnmanaged(void) = .{};
13491349 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);
13511351 for (options.system_libs) |lib_name| {
13521352 system_libs.putAssumeCapacity(lib_name, {});
13531353 }
......@@ -1483,7 +1483,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14831483 errdefer comp.astgen_wait_group.deinit();
14841484
14851485 // 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);
14871487 for (options.c_source_files) |c_source_file| {
14881488 const c_object = try gpa.create(CObject);
14891489 errdefer gpa.destroy(c_object);
......@@ -3084,7 +3084,7 @@ pub fn addCCArgs(
30843084
30853085 // It would be really nice if there was a more compact way to communicate this info to Clang.
30863086 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);
30883088 for (all_features_list) |feature, index_usize| {
30893089 const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize);
30903090 const is_enabled = target.cpu.features.isEnabled(index);
......@@ -3334,7 +3334,7 @@ fn failCObjWithOwnedErrorMsg(
33343334 defer lock.release();
33353335 {
33363336 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);
33383338 }
33393339 comp.failed_c_objects.putAssumeCapacityNoClobber(c_object, err_msg);
33403340 }
......@@ -3585,7 +3585,7 @@ fn detectLibCIncludeDirs(
35853585
35863586fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs {
35873587 var list = std.ArrayList([]const u8).init(arena);
3588 try list.ensureCapacity(4);
3588 try list.ensureTotalCapacity(4);
35893589
35903590 list.appendAssumeCapacity(lci.include_dir.?);
35913591
......@@ -3692,7 +3692,7 @@ fn setMiscFailure(
36923692 comptime format: []const u8,
36933693 args: anytype,
36943694) 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);
36963696 const msg = try std.fmt.allocPrint(comp.gpa, format, args);
36973697 comp.misc_failures.putAssumeCapacityNoClobber(tag, .{ .msg = msg });
36983698}
......@@ -4027,7 +4027,7 @@ fn buildOutputFromZig(
40274027 defer if (!keep_errors) errors.deinit(sub_compilation.gpa);
40284028
40294029 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);
40314031 comp.misc_failures.putAssumeCapacityNoClobber(misc_task_tag, .{
40324032 .msg = try std.fmt.allocPrint(comp.gpa, "sub-compilation of {s} failed", .{
40334033 @tagName(misc_task_tag),
......@@ -4459,7 +4459,7 @@ pub fn build_crt_file(
44594459
44604460 try sub_compilation.updateSubCompilation();
44614461
4462 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);
4462 try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1);
44634463
44644464 comp.crt_files.putAssumeCapacityNoClobber(basename, .{
44654465 .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(
454454 }
455455 // Now we have to correctly populate new_set.
456456 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()));
458458 var it = then_table.keyIterator();
459459 while (it.next()) |key| {
460460 _ = ns.putAssumeCapacity(key.*, {});
src/Module.zig+2-2
......@@ -3504,7 +3504,7 @@ pub fn scanNamespace(
35043504 const zir = namespace.file_scope.zir;
35053505
35063506 try mod.comp.work_queue.ensureUnusedCapacity(decls_len);
3507 try namespace.decls.ensureCapacity(gpa, decls_len);
3507 try namespace.decls.ensureTotalCapacity(gpa, decls_len);
35083508
35093509 const bit_bags_count = std.math.divCeil(usize, decls_len, 8) catch unreachable;
35103510 var extra_index = extra_start + bit_bags_count;
......@@ -4071,7 +4071,7 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged
40714071 }
40724072
40734073 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);
40754075 gop.key_ptr.* = try mod.gpa.dupe(u8, name);
40764076 gop.value_ptr.* = @intCast(ErrorInt, mod.error_name_list.items.len);
40774077 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 {
111111}
112112
113113pub 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);
115115 const name_dupe = try mem.dupe(gpa, u8, name);
116116 pkg.table.putAssumeCapacityNoClobber(name_dupe, package);
117117}
src/Sema.zig+4-4
......@@ -1130,7 +1130,7 @@ fn zirEnumDecl(
11301130 const body_end = extra_index;
11311131 extra_index += bit_bags_count;
11321132
1133 try enum_obj.fields.ensureCapacity(&new_decl_arena.allocator, fields_len);
1133 try enum_obj.fields.ensureTotalCapacity(&new_decl_arena.allocator, fields_len);
11341134 const any_values = for (sema.code.extra[body_end..][0..bit_bags_count]) |bag| {
11351135 if (bag != 0) break true;
11361136 } else false;
......@@ -3484,7 +3484,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
34843484 },
34853485 .error_set => {
34863486 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);
34883488 for (lhs_set.names_ptr[0..lhs_set.names_len]) |name| {
34893489 set.putAssumeCapacityNoClobber(name, {});
34903490 }
......@@ -3498,7 +3498,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
34983498 },
34993499 .error_set => {
35003500 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);
35023502 for (rhs_set.names_ptr[0..rhs_set.names_len]) |name| {
35033503 set.putAssumeCapacity(name, {});
35043504 }
......@@ -10361,7 +10361,7 @@ fn analyzeUnionFields(
1036110361 var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa);
1036210362 defer union_obj.owner_decl.value_arena.?.* = decl_arena.state;
1036310363
10364 try union_obj.fields.ensureCapacity(&decl_arena.allocator, fields_len);
10364 try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);
1036510365
1036610366 if (body.len != 0) {
1036710367 _ = try sema.analyzeBody(block, body);
src/codegen.zig+17-17
......@@ -141,7 +141,7 @@ pub fn generateSymbol(
141141 // TODO populate .debug_info for the array
142142 if (typed_value.val.castTag(.bytes)) |payload| {
143143 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);
145145 code.appendSliceAssumeCapacity(payload.data);
146146 switch (try generateSymbol(bin_file, src_loc, .{
147147 .ty = typed_value.ty.elemType(),
......@@ -568,7 +568,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
568568 fn gen(self: *Self) !void {
569569 switch (arch) {
570570 .x86_64 => {
571 try self.code.ensureCapacity(self.code.items.len + 11);
571 try self.code.ensureUnusedCapacity(11);
572572
573573 const cc = self.fn_type.fnCallingConvention();
574574 if (cc != .Naked) {
......@@ -607,7 +607,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
607607 // Important to be after the possible self.code.items.len -= 5 above.
608608 try self.dbgSetEpilogueBegin();
609609
610 try self.code.ensureCapacity(self.code.items.len + 9);
610 try self.code.ensureUnusedCapacity(9);
611611 // add rsp, x
612612 if (aligned_stack_end > math.maxInt(i8)) {
613613 // example: 48 81 c4 ff ff ff 7f add rsp,0x7fffffff
......@@ -1960,7 +1960,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
19601960 //
19611961 // TODO: make this algorithm less bad
19621962
1963 try self.code.ensureCapacity(self.code.items.len + 8);
1963 try self.code.ensureUnusedCapacity(8);
19641964
19651965 const lhs = try self.resolveInst(op_lhs);
19661966 const rhs = try self.resolveInst(op_rhs);
......@@ -2447,13 +2447,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24472447 .register => |reg| {
24482448 switch (self.debug_output) {
24492449 .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);
24512451 dbg_out.dbg_info.appendAssumeCapacity(link.File.Elf.abbrev_parameter);
24522452 dbg_out.dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
24532453 1, // ULEB128 dwarf expression length
24542454 reg.dwarfLocOp(),
24552455 });
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);
24572457 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
24582458 dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
24592459 },
......@@ -2484,7 +2484,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24842484 try dbg_out.dbg_info.append(DW.OP.breg11);
24852485 try leb128.writeILEB128(dbg_out.dbg_info.writer(), adjusted_stack_offset);
24862486
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);
24882488 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
24892489 dbg_out.dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
24902490 },
......@@ -2626,7 +2626,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
26262626 unreachable;
26272627
26282628 // 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);
26302630 self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 });
26312631 mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), got_addr);
26322632 } else if (func_value.castTag(.extern_fn)) |_| {
......@@ -2839,7 +2839,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
28392839 .memory = func.owner_decl.link.macho.local_sym_index,
28402840 });
28412841 // callq *%rax
2842 try self.code.ensureCapacity(self.code.items.len + 2);
2842 try self.code.ensureUnusedCapacity(2);
28432843 self.code.appendSliceAssumeCapacity(&[2]u8{ 0xff, 0xd0 });
28442844 },
28452845 .aarch64 => {
......@@ -2858,7 +2858,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
28582858 switch (arch) {
28592859 .x86_64 => {
28602860 // callq
2861 try self.code.ensureCapacity(self.code.items.len + 5);
2861 try self.code.ensureUnusedCapacity(5);
28622862 self.code.appendSliceAssumeCapacity(&[5]u8{ 0xe8, 0x0, 0x0, 0x0, 0x0 });
28632863 break :blk @intCast(u32, self.code.items.len) - 4;
28642864 },
......@@ -2932,7 +2932,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29322932 const got_addr = p9.bases.data;
29332933 const got_index = func_payload.data.owner_decl.link.plan9.got_index.?;
29342934 // 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);
29362936 self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 });
29372937 const fn_got_addr = got_addr + got_index * ptr_bytes;
29382938 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 {
30753075 const rhs = try self.resolveInst(bin_op.rhs);
30763076 const result: MCValue = switch (arch) {
30773077 .x86_64 => result: {
3078 try self.code.ensureCapacity(self.code.items.len + 8);
3078 try self.code.ensureUnusedCapacity(8);
30793079
30803080 // There are 2 operands, destination and source.
30813081 // Either one, but not both, can be a memory operand.
......@@ -3159,7 +3159,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
31593159
31603160 const reloc: Reloc = switch (arch) {
31613161 .i386, .x86_64 => reloc: {
3162 try self.code.ensureCapacity(self.code.items.len + 6);
3162 try self.code.ensureUnusedCapacity(6);
31633163
31643164 const opcode: u8 = switch (cond) {
31653165 .compare_flags_signed => |cmp_op| blk: {
......@@ -3519,7 +3519,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
35193519 fn jump(self: *Self, index: usize) !void {
35203520 switch (arch) {
35213521 .i386, .x86_64 => {
3522 try self.code.ensureCapacity(self.code.items.len + 5);
3522 try self.code.ensureUnusedCapacity(5);
35233523 if (math.cast(i8, @intCast(i32, index) - (@intCast(i32, self.code.items.len + 2)))) |delta| {
35243524 self.code.appendAssumeCapacity(0xeb); // jmp rel8
35253525 self.code.appendAssumeCapacity(@bitCast(u8, delta));
......@@ -3657,7 +3657,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
36573657 const block_data = self.blocks.getPtr(block).?;
36583658
36593659 // 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);
36613661
36623662 switch (arch) {
36633663 .i386, .x86_64 => {
......@@ -4041,7 +4041,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
40414041 if (adj_off > 128) {
40424042 return self.fail("TODO implement set stack variable with large stack offset", .{});
40434043 }
4044 try self.code.ensureCapacity(self.code.items.len + 8);
4044 try self.code.ensureUnusedCapacity(8);
40454045 switch (abi_size) {
40464046 1 => {
40474047 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 {
40674067
40684068 // 64 bit write to memory would take two mov's anyways so we
40694069 // 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);
40714071 var buf: [8]u8 = undefined;
40724072 mem.writeIntLittle(u64, &buf, x_big);
40734073
src/codegen/spirv.zig+1-1
......@@ -629,7 +629,7 @@ pub const DeclGen = struct {
629629 const params = decl.ty.fnParamLen();
630630 var i: usize = 0;
631631
632 try self.args.ensureCapacity(params);
632 try self.args.ensureTotalCapacity(params);
633633 while (i < params) : (i += 1) {
634634 const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?;
635635 const arg_result_id = self.spv.allocResultId();
src/libcxx.zig+2-2
......@@ -108,7 +108,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
108108 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
109109 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
110110 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);
112112
113113 for (libcxx_files) |cxx_src| {
114114 var cflags = std.ArrayList([]const u8).init(arena);
......@@ -246,7 +246,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
246246 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
247247 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
248248 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);
250250
251251 for (libcxxabi_files) |cxxabi_src| {
252252 var cflags = std.ArrayList([]const u8).init(arena);
src/libtsan.zig+6-6
......@@ -34,7 +34,7 @@ pub fn buildTsan(comp: *Compilation) !void {
3434 };
3535
3636 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);
3838
3939 const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"tsan"});
4040 for (tsan_sources) |tsan_src| {
......@@ -58,7 +58,7 @@ pub fn buildTsan(comp: *Compilation) !void {
5858 &darwin_tsan_sources
5959 else
6060 &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);
6262 for (platform_tsan_sources) |tsan_src| {
6363 var cflags = std.ArrayList([]const u8).init(arena);
6464
......@@ -96,7 +96,7 @@ pub fn buildTsan(comp: *Compilation) !void {
9696 });
9797 }
9898
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);
100100 const sanitizer_common_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
101101 "tsan", "sanitizer_common",
102102 });
......@@ -123,7 +123,7 @@ pub fn buildTsan(comp: *Compilation) !void {
123123 &sanitizer_libcdep_sources
124124 else
125125 &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);
127127 for (to_c_or_not_to_c_sources) |c_src| {
128128 var cflags = std.ArrayList([]const u8).init(arena);
129129
......@@ -143,7 +143,7 @@ pub fn buildTsan(comp: *Compilation) !void {
143143 });
144144 }
145145
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);
147147 for (sanitizer_symbolizer_sources) |c_src| {
148148 var cflags = std.ArrayList([]const u8).init(arena);
149149
......@@ -168,7 +168,7 @@ pub fn buildTsan(comp: *Compilation) !void {
168168 &[_][]const u8{"interception"},
169169 );
170170
171 try c_source_files.ensureCapacity(c_source_files.items.len + interception_sources.len);
171 try c_source_files.ensureUnusedCapacity(interception_sources.len);
172172 for (interception_sources) |c_src| {
173173 var cflags = std.ArrayList([]const u8).init(arena);
174174
src/link.zig+1-1
......@@ -635,7 +635,7 @@ pub const File = struct {
635635 var object_files = std.ArrayList([*:0]const u8).init(base.allocator);
636636 defer object_files.deinit();
637637
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);
639639 for (base.options.objects) |obj_path| {
640640 object_files.appendAssumeCapacity(try arena.dupeZ(u8, obj_path));
641641 }
src/link/C.zig+3-3
......@@ -197,7 +197,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {
197197 defer all_buffers.deinit();
198198
199199 // 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);
201201
202202 var file_size: u64 = zig_h.len;
203203 all_buffers.appendAssumeCapacity(.{
......@@ -258,7 +258,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {
258258 file_size += err_typedef_buf.items.len;
259259
260260 // Now the function bodies.
261 try all_buffers.ensureCapacity(all_buffers.items.len + fn_count);
261 try all_buffers.ensureUnusedCapacity(fn_count);
262262 for (self.decl_table.keys()) |decl| {
263263 if (!decl.has_tv) continue;
264264 if (decl.val.castTag(.function)) |_| {
......@@ -286,7 +286,7 @@ pub fn flushEmitH(module: *Module) !void {
286286 var all_buffers = std.ArrayList(std.os.iovec_const).init(module.gpa);
287287 defer all_buffers.deinit();
288288
289 try all_buffers.ensureCapacity(emit_h.decl_table.count() + 1);
289 try all_buffers.ensureTotalCapacity(emit_h.decl_table.count() + 1);
290290
291291 var file_size: u64 = zig_h.len;
292292 all_buffers.appendAssumeCapacity(.{
src/link/Coff.zig+3-3
......@@ -418,7 +418,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff {
418418pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void {
419419 if (self.llvm_object) |_| return;
420420
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);
422422
423423 if (self.offset_table_free_list.popOrNull()) |i| {
424424 decl.link.coff.offset_table_index = i;
......@@ -793,7 +793,7 @@ pub fn updateDeclExports(
793793 for (exports) |exp| {
794794 if (exp.options.section) |section_name| {
795795 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);
797797 module.failed_exports.putAssumeCapacityNoClobber(
798798 exp,
799799 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}),
......@@ -804,7 +804,7 @@ pub fn updateDeclExports(
804804 if (mem.eql(u8, exp.options.name, "_start")) {
805805 self.entry_addr = decl.link.coff.getVAddr(self.*) - default_image_base;
806806 } else {
807 try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1);
807 try module.failed_exports.ensureUnusedCapacity(module.gpa, 1);
808808 module.failed_exports.putAssumeCapacityNoClobber(
809809 exp,
810810 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 {
411411
412412/// TODO Improve this to use a table.
413413fn 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);
415415 const result = self.shstrtab.items.len;
416416 self.shstrtab.appendSliceAssumeCapacity(bytes);
417417 self.shstrtab.appendAssumeCapacity(0);
......@@ -420,7 +420,7 @@ fn makeString(self: *Elf, bytes: []const u8) !u32 {
420420
421421/// TODO Improve this to use a table.
422422fn 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);
424424 const result = self.debug_strtab.items.len;
425425 self.debug_strtab.appendSliceAssumeCapacity(bytes);
426426 self.debug_strtab.appendAssumeCapacity(0);
......@@ -856,7 +856,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
856856
857857 // We have a function to compute the upper bound size, because it's needed
858858 // 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());
860860
861861 // initial length - length of the .debug_info contribution for this compilation unit,
862862 // not including the initial length itself.
......@@ -925,7 +925,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
925925
926926 // Enough for all the data without resizing. When support for more compilation units
927927 // is added, the size of this section will become more variable.
928 try di_buf.ensureCapacity(100);
928 try di_buf.ensureTotalCapacity(100);
929929
930930 // initial length - length of the .debug_aranges contribution for this compilation unit,
931931 // not including the initial length itself.
......@@ -1004,7 +1004,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
10041004 // The size of this header is variable, depending on the number of directories,
10051005 // files, and padding. We have a function to compute the upper bound size, however,
10061006 // 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());
10081008
10091009 // initial length - length of the .debug_line contribution for this compilation unit,
10101010 // not including the initial length itself.
......@@ -1639,7 +1639,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
16391639 // Shared libraries.
16401640 if (is_exe_or_dyn_lib) {
16411641 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);
16431643 for (system_libs) |link_lib| {
16441644 // By this time, we depend on these libs being dynamically linked libraries and not static libraries
16451645 // (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 {
21132113
21142114 if (decl.link.elf.local_sym_index != 0) return;
21152115
2116 try self.local_symbols.ensureCapacity(self.base.allocator, self.local_symbols.items.len + 1);
2117 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
2116 try self.local_symbols.ensureUnusedCapacity(self.base.allocator, 1);
2117 try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1);
21182118
21192119 if (self.local_symbol_free_list.popOrNull()) |i| {
21202120 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
23162316 defer deinitRelocs(self.base.allocator, &dbg_info_type_relocs);
23172317
23182318 // 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);
23202320
23212321 const decl = func.owner_decl;
23222322 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
23512351
23522352 // .debug_info subprogram
23532353 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);
23552355
23562356 const fn_ret_type = decl.ty.fnReturnType();
23572357 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
25932593 },
25942594 .Int => {
25952595 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);
25972597 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);
25982598 // DW.AT.encoding, DW.FORM.data1
25992599 dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) {
......@@ -2607,7 +2607,7 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo
26072607 },
26082608 .Optional => {
26092609 if (ty.isPtrLikeOptional()) {
2610 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12);
2610 try dbg_info_buffer.ensureUnusedCapacity(12);
26112611 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);
26122612 // DW.AT.encoding, DW.FORM.data1
26132613 dbg_info_buffer.appendAssumeCapacity(DW.ATE.address);
......@@ -2747,14 +2747,14 @@ pub fn updateDeclExports(
27472747 const tracy = trace(@src());
27482748 defer tracy.end();
27492749
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);
27512751 if (decl.link.elf.local_sym_index == 0) return;
27522752 const decl_sym = self.local_symbols.items[decl.link.elf.local_sym_index];
27532753
27542754 for (exports) |exp| {
27552755 if (exp.options.section) |section_name| {
27562756 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);
27582758 module.failed_exports.putAssumeCapacityNoClobber(
27592759 exp,
27602760 try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}),
......@@ -2772,7 +2772,7 @@ pub fn updateDeclExports(
27722772 },
27732773 .Weak => elf.STB_WEAK,
27742774 .LinkOnce => {
2775 try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.count() + 1);
2775 try module.failed_exports.ensureUnusedCapacity(module.gpa, 1);
27762776 module.failed_exports.putAssumeCapacityNoClobber(
27772777 exp,
27782778 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(
102102 var buffer = try allocator.alloc(u8, page_size);
103103 defer allocator.free(buffer);
104104
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);
106106
107107 // 1. Save the identifier and update offsets
108108 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
353353
354354 // We have a function to compute the upper bound size, because it's needed
355355 // 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());
357357
358358 // initial length - length of the .debug_info contribution for this compilation unit,
359359 // not including the initial length itself.
......@@ -408,7 +408,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
408408
409409 // Enough for all the data without resizing. When support for more compilation units
410410 // is added, the size of this section will become more variable.
411 try di_buf.ensureCapacity(100);
411 try di_buf.ensureTotalCapacity(100);
412412
413413 // initial length - length of the .debug_aranges contribution for this compilation unit,
414414 // not including the initial length itself.
......@@ -479,7 +479,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
479479 // The size of this header is variable, depending on the number of directories,
480480 // files, and padding. We have a function to compute the upper bound size, however,
481481 // 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));
483483
484484 // initial length - length of the .debug_line contribution for this compilation unit,
485485 // not including the initial length itself.
......@@ -607,7 +607,7 @@ fn copySegmentCommand(self: *DebugSymbols, allocator: *Allocator, base_cmd: Segm
607607 };
608608 mem.copy(u8, &cmd.inner.segname, &base_cmd.inner.segname);
609609
610 try cmd.sections.ensureCapacity(allocator, cmd.inner.nsects);
610 try cmd.sections.ensureTotalCapacity(allocator, cmd.inner.nsects);
611611 for (base_cmd.sections.items) |base_sect, i| {
612612 var sect = macho.section_64{
613613 .sectname = undefined,
......@@ -855,7 +855,7 @@ pub fn initDeclDebugBuffers(
855855 switch (decl.ty.zigTypeTag()) {
856856 .Fn => {
857857 // 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);
859859
860860 const func = decl.val.castTag(.function).?.data;
861861 const line_off = @intCast(u28, decl.src_line + func.lbrace_line);
......@@ -889,7 +889,7 @@ pub fn initDeclDebugBuffers(
889889
890890 // .debug_info subprogram
891891 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);
893893
894894 const fn_ret_type = decl.ty.fnReturnType();
895895 const fn_ret_has_bits = fn_ret_type.hasCodeGenBits();
......@@ -1124,7 +1124,7 @@ fn addDbgInfoType(
11241124 },
11251125 .Int => {
11261126 const info = ty.intInfo(target);
1127 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12);
1127 try dbg_info_buffer.ensureUnusedCapacity(12);
11281128 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);
11291129 // DW.AT.encoding, DW.FORM.data1
11301130 dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) {
......@@ -1261,7 +1261,7 @@ fn getDebugLineProgramEnd(self: DebugSymbols) u32 {
12611261
12621262/// TODO Improve this to use a table.
12631263fn 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);
12651265 const result = self.debug_string_table.items.len;
12661266 self.debug_string_table.appendSliceAssumeCapacity(bytes);
12671267 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 {
180180fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void {
181181 const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0;
182182
183 try self.load_commands.ensureCapacity(allocator, self.header.?.ncmds);
183 try self.load_commands.ensureTotalCapacity(allocator, self.header.?.ncmds);
184184
185185 var i: u16 = 0;
186186 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) !
261261 const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition.
262262 const offset = self.file_offset orelse 0;
263263
264 try self.load_commands.ensureCapacity(allocator, header.ncmds);
264 try self.load_commands.ensureTotalCapacity(allocator, header.ncmds);
265265
266266 var i: u16 = 0;
267267 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 {
326326 if (!self.trie_dirty) return;
327327
328328 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);
330330
331331 var fifo = std.fifo.LinearFifo(*Node, .Dynamic).init(allocator);
332332 defer fifo.deinit();
src/link/MachO/commands.zig+1-1
......@@ -223,7 +223,7 @@ pub const SegmentCommand = struct {
223223 var segment = SegmentCommand{
224224 .inner = inner,
225225 };
226 try segment.sections.ensureCapacity(alloc, inner.nsects);
226 try segment.sections.ensureTotalCapacity(alloc, inner.nsects);
227227
228228 var i: usize = 0;
229229 while (i < inner.nsects) : (i += 1) {
src/link/Wasm.zig+2-2
......@@ -172,8 +172,8 @@ pub fn deinit(self: *Wasm) void {
172172pub fn allocateDeclIndexes(self: *Wasm, decl: *Module.Decl) !void {
173173 if (decl.link.wasm.init) return;
174174
175 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
176 try self.symbols.ensureCapacity(self.base.allocator, self.symbols.items.len + 1);
175 try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1);
176 try self.symbols.ensureUnusedCapacity(self.base.allocator, 1);
177177
178178 const block = &decl.link.wasm;
179179 block.init = true;
src/main.zig+6-6
......@@ -1704,22 +1704,22 @@ fn buildOutputType(
17041704 } else true;
17051705 if (!should_get_sdk_path) break :outer false;
17061706 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);
17081708 clang_argv.appendAssumeCapacity("-isysroot");
17091709 clang_argv.appendAssumeCapacity(sdk_path);
17101710 break :outer true;
17111711 } else break :outer false;
17121712 } else false;
17131713
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);
17151715 const isystem_flag = if (has_sysroot) "-iwithsysroot" else "-isystem";
17161716 for (paths.include_dirs.items) |include_dir| {
17171717 clang_argv.appendAssumeCapacity(isystem_flag);
17181718 clang_argv.appendAssumeCapacity(include_dir);
17191719 }
17201720
1721 try clang_argv.ensureCapacity(clang_argv.items.len + paths.framework_dirs.items.len * 2);
1722 try framework_dirs.ensureCapacity(framework_dirs.items.len + paths.framework_dirs.items.len);
1721 try clang_argv.ensureUnusedCapacity(paths.framework_dirs.items.len * 2);
1722 try framework_dirs.ensureUnusedCapacity(paths.framework_dirs.items.len);
17231723 const iframework_flag = if (has_sysroot) "-iframeworkwithsysroot" else "-iframework";
17241724 for (paths.framework_dirs.items) |framework_dir| {
17251725 clang_argv.appendAssumeCapacity(iframework_flag);
......@@ -2783,7 +2783,7 @@ pub fn cmdInit(
27832783 fatal("unable to read template file 'build.zig': {s}", .{@errorName(err)});
27842784 };
27852785 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);
27872787 for (build_zig_contents) |c| {
27882788 if (c == '$') {
27892789 try modified_build_zig_contents.appendSlice(cwd_basename);
......@@ -3464,7 +3464,7 @@ fn fmtPathFile(
34643464
34653465 // As a heuristic, we make enough capacity for the same as the input source.
34663466 fmt.out_buffer.shrinkRetainingCapacity(0);
3467 try fmt.out_buffer.ensureCapacity(source_code.len);
3467 try fmt.out_buffer.ensureTotalCapacity(source_code.len);
34683468
34693469 try tree.renderToArrayList(&fmt.out_buffer);
34703470 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 {
312312 if (try man.hit()) {
313313 const digest = man.final();
314314
315 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);
315 try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1);
316316 comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{
317317 .full_object_path = try comp.global_cache_directory.join(comp.gpa, &[_][]const u8{
318318 "o", &digest, final_lib_basename,
src/musl.zig+2-2
......@@ -112,7 +112,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
112112 var source_table = std.StringArrayHashMap(Ext).init(comp.gpa);
113113 defer source_table.deinit();
114114
115 try source_table.ensureCapacity(compat_time32_files.len + src_files.len);
115 try source_table.ensureTotalCapacity(compat_time32_files.len + src_files.len);
116116
117117 for (src_files) |src_file| {
118118 try addSrcFile(arena, &source_table, src_file);
......@@ -231,7 +231,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
231231
232232 try sub_compilation.updateSubCompilation();
233233
234 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);
234 try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1);
235235
236236 const basename = try comp.gpa.dupe(u8, "libc.so");
237237 errdefer comp.gpa.free(basename);
src/translate_c.zig+1-1
......@@ -4882,7 +4882,7 @@ fn finishTransFnProto(
48824882 var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa);
48834883 defer fn_params.deinit();
48844884 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);
48864886
48874887 var i: usize = 0;
48884888 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 {
728728
729729 // Estimate that each top level node has 10 child nodes.
730730 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);
732732 // Estimate that each each node has 2 tokens.
733733 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);
735735 // Estimate that each each token is 3 bytes long.
736736 const estimated_buf_len = estimated_tokens_count * 3;
737 try ctx.buf.ensureCapacity(estimated_buf_len);
737 try ctx.buf.ensureTotalCapacity(estimated_buf_len);
738738
739739 ctx.nodes.appendAssumeCapacity(.{
740740 .tag = .root,
......@@ -839,7 +839,7 @@ const Context = struct {
839839
840840 fn addExtra(c: *Context, extra: anytype) Allocator.Error!NodeIndex {
841841 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);
843843 const result = @intCast(u32, c.extra_data.items.len);
844844 inline for (fields) |field| {
845845 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
27972797 _ = try c.addToken(.l_paren, "(");
27982798 var rendered = std.ArrayList(NodeIndex).init(c.gpa);
27992799 errdefer rendered.deinit();
2800 try rendered.ensureCapacity(std.math.max(params.len, 1));
2800 try rendered.ensureTotalCapacity(std.math.max(params.len, 1));
28012801
28022802 for (params) |param, i| {
28032803 if (i != 0) _ = try c.addToken(.comma, ",");