authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-18 05:28:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-18 16:41:54-07:00
logb75d86027d589be632a831ec55565230818dc4ef
tree4770cc0353d88bb1d02862222358c83843b275b1
parentb03345f32a5ba2849ddbeeae0e31e0e77ca01b01

stage2: avoid binary bloat from GeneralPurposeAllocator

In the case of not using it.

1 files changed, 3 insertions(+), 4 deletions(-)

src/main.zig+3-4
...@@ -135,10 +135,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{...@@ -135,10 +135,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{
135pub fn main() anyerror!void {135pub fn main() anyerror!void {
136 crash_report.initialize();136 crash_report.initialize();
137137
138 var gpa_need_deinit = false;138 const use_gpa = build_options.force_gpa or !builtin.link_libc;
139 const gpa = gpa: {139 const gpa = gpa: {
140 if (build_options.force_gpa or !builtin.link_libc) {140 if (use_gpa) {
141 gpa_need_deinit = true;
142 break :gpa general_purpose_allocator.allocator();141 break :gpa general_purpose_allocator.allocator();
143 }142 }
144 // We would prefer to use raw libc allocator here, but cannot143 // We would prefer to use raw libc allocator here, but cannot
...@@ -148,7 +147,7 @@ pub fn main() anyerror!void {...@@ -148,7 +147,7 @@ pub fn main() anyerror!void {
148 }147 }
149 break :gpa std.heap.raw_c_allocator;148 break :gpa std.heap.raw_c_allocator;
150 };149 };
151 defer if (gpa_need_deinit) {150 defer if (use_gpa) {
152 _ = general_purpose_allocator.deinit();151 _ = general_purpose_allocator.deinit();
153 };152 };
154 var arena_instance = std.heap.ArenaAllocator.init(gpa);153 var arena_instance = std.heap.ArenaAllocator.init(gpa);