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.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.zig')
| -rw-r--r-- | src/link.zig | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/link.zig b/src/link.zig index 3ff73fb7bf..762c6f9212 100644 --- a/src/link.zig +++ b/src/link.zig @@ -650,10 +650,10 @@ pub const File = struct { }; } - var object_files = std.ArrayList([*:0]const u8).init(base.allocator); + const num_object_files = base.options.objects.len + comp.c_object_table.count() + 2; + var object_files = try std.ArrayList([*:0]const u8).initCapacity(base.allocator, num_object_files); defer object_files.deinit(); - try object_files.ensureTotalCapacity(base.options.objects.len + comp.c_object_table.count() + 2); for (base.options.objects) |obj_path| { object_files.appendAssumeCapacity(try arena.dupeZ(u8, obj_path)); } |
