Skip to content

Commit

Permalink
Preprocessor: allocate space before appending
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jul 18, 2024
1 parent efb35a1 commit e8e87cf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e8e87cf

Please sign in to comment.