zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a34375814106dbc0e0181bca7cc4ffb1821cb51e (tree)
parent f49d42729a22846ec54b6610db415ac8cdaa31db
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Mon,  1 Nov 2021 00:56:55 -0700

Update ensureTotalCapacity to ensureTotalCapacityPrecise where it makes sense

These calls are all late-initialization of ArrayList's that were initialized outside the current scope. This allows us to still get the potential memory-saving benefits of the 'precision' of initCapacity.

Diffstat:
Mlib/std/coff.zig | 4++--
Msrc/Module.zig | 2+-
Msrc/link/MachO/CodeSignature.zig | 2+-
Msrc/link/MachO/commands.zig | 2+-
4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/std/coff.zig b/lib/std/coff.zig @@ -276,7 +276,7 @@ pub const Coff = struct { if (self.sections.items.len == self.coff_header.number_of_sections) return; - try self.sections.ensureTotalCapacity(self.coff_header.number_of_sections); + try self.sections.ensureTotalCapacityPrecise(self.coff_header.number_of_sections); const in = self.in_file.reader(); @@ -297,7 +297,7 @@ pub const Coff = struct { std.mem.set(u8, name[8..], 0); } - try self.sections.append(Section{ + self.sections.appendAssumeCapacity(Section{ .header = SectionHeader{ .name = name, .misc = SectionHeader.Misc{ .virtual_size = try in.readIntLittle(u32) }, diff --git a/src/Module.zig b/src/Module.zig @@ -4146,7 +4146,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: *Allocator) Se // for the runtime ones. const fn_ty = decl.ty; const runtime_params_len = @intCast(u32, fn_ty.fnParamLen()); - try inner_block.instructions.ensureTotalCapacity(gpa, runtime_params_len); + try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len); try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType` try sema.inst_map.ensureUnusedCapacity(gpa, fn_info.total_params_len); diff --git a/src/link/MachO/CodeSignature.zig b/src/link/MachO/CodeSignature.zig @@ -102,7 +102,7 @@ pub fn calcAdhocSignature( var buffer = try allocator.alloc(u8, page_size); defer allocator.free(buffer); - try cdir.data.ensureTotalCapacity(allocator, total_pages * hash_size + id.len + 1); + try cdir.data.ensureTotalCapacityPrecise(allocator, total_pages * hash_size + id.len + 1); // 1. Save the identifier and update offsets cdir.inner.identOffset = cdir.inner.length; diff --git a/src/link/MachO/commands.zig b/src/link/MachO/commands.zig @@ -223,7 +223,7 @@ pub const SegmentCommand = struct { var segment = SegmentCommand{ .inner = inner, }; - try segment.sections.ensureTotalCapacity(alloc, inner.nsects); + try segment.sections.ensureTotalCapacityPrecise(alloc, inner.nsects); var i: usize = 0; while (i < inner.nsects) : (i += 1) {