diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2021-11-01 00:54:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-11-04 14:54:25 -0400 |
| commit | e97feb96e4daf7d53538c9c8773d50459a59e5ee (patch) | |
| tree | 33474da46590a20370d970d033a3123b620b2f81 /src/link/MachO/Object.zig | |
| parent | d03e9d0b8347a74d674bdafadb71e7ddd8fdfad1 (diff) | |
| download | zig-e97feb96e4daf7d53538c9c8773d50459a59e5ee.tar.gz zig-e97feb96e4daf7d53538c9c8773d50459a59e5ee.zip | |
Replace ArrayList.init/ensureTotalCapacity pairs with initCapacity
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 21a0686fef..7b4828c740 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -393,9 +393,8 @@ pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) // local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance, // the GO compiler does not necessarily respect that therefore we sort immediately by type // and address within. - var sorted_all_nlists = std.ArrayList(NlistWithIndex).init(allocator); + var sorted_all_nlists = try std.ArrayList(NlistWithIndex).initCapacity(allocator, self.symtab.items.len); defer sorted_all_nlists.deinit(); - try sorted_all_nlists.ensureTotalCapacity(self.symtab.items.len); for (self.symtab.items) |nlist, index| { sorted_all_nlists.appendAssumeCapacity(.{ |
