From 56bd4100444a6f0219efc4c203aa252e1878caa6 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 7 May 2023 23:52:05 -0700 Subject: [PATCH] Reduce over-allocation --- src/bundler/bundle_v2.zig | 6 +++--- src/multi_array_list.zig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 9b7aa3c57d..24e6f8b3c2 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -3136,7 +3136,7 @@ const LinkerGraph = struct { dynamic_import_entry_points: []const Index.Int, shadow_entry_point_range: Logger.Range, ) !void { - try this.files.ensureTotalCapacity(this.allocator, sources.len); + try this.files.setCapacity(this.allocator, sources.len); this.files.zero(); this.files_live = try BitSet.initEmpty( this.allocator, @@ -3153,7 +3153,7 @@ const LinkerGraph = struct { // Setup entry points { - try this.entry_points.ensureTotalCapacity(this.allocator, entry_points.len + use_directive_entry_points.len + dynamic_import_entry_points.len); + try this.entry_points.setCapacity(this.allocator, entry_points.len + use_directive_entry_points.len + dynamic_import_entry_points.len); this.entry_points.len = entry_points.len; var source_indices = this.entry_points.items(.source_index); @@ -3192,7 +3192,7 @@ const LinkerGraph = struct { } var import_records_list: []ImportRecord.List = this.ast.items(.import_records); - try this.meta.ensureTotalCapacity(this.allocator, import_records_list.len); + try this.meta.setCapacity(this.allocator, import_records_list.len); this.meta.len = this.ast.len; this.meta.zero(); diff --git a/src/multi_array_list.zig b/src/multi_array_list.zig index e4249ae4ba..d7e3c98e61 100644 --- a/src/multi_array_list.zig +++ b/src/multi_array_list.zig @@ -393,7 +393,7 @@ pub fn MultiArrayList(comptime S: type) type { pub fn clone(self: Self, gpa: Allocator) !Self { var result = Self{}; errdefer result.deinit(gpa); - try result.ensureTotalCapacity(gpa, self.len); + try result.setCapacity(gpa, self.len); result.len = self.len; const self_slice = self.slice(); const result_slice = result.slice();