From e8e87cf9649383ed42f76d328c1b7d516ad4e13f Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Thu, 18 Jul 2024 16:19:04 -0700 Subject: [PATCH] Preprocessor: allocate space before appending --- src/aro/Preprocessor.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aro/Preprocessor.zig b/src/aro/Preprocessor.zig index d0eae66c..3bdfd4d9 100644 --- a/src/aro/Preprocessor.zig +++ b/src/aro/Preprocessor.zig @@ -600,10 +600,10 @@ fn stringize(pp: *Preprocessor, tmpl: PreprocessorToken, args_range: MacroArg) ! const args = args_range.slice(pp.macro_arg_tokens.items); for (args, 0..) |tok, i| { const slice = pp.tokSlice(tok); - if (slice.len > 0 and tok.flags.space and i != 0) { - try pp.comp.generated_buf.append(pp.gpa, ' '); - } - try pp.comp.generated_buf.appendSlice(pp.gpa, slice); + const needs_space = slice.len > 0 and tok.flags.space and i != 0; + const bytes_needed = slice.len + @intFromBool(needs_space); + try pp.comp.generated_buf.ensureUnusedCapacity(pp.gpa, bytes_needed); + pp.comp.generated_buf.appendSliceAssumeCapacity(pp.tokSlice(tok)); } try pp.comp.generated_buf.append(pp.gpa, '"'); var tok = tmpl;