From 34644511bb6d83aa6575641ef79e5eefb495e3e1 Mon Sep 17 00:00:00 2001 From: rpkak Date: Mon, 6 Jan 2025 12:06:52 +0100 Subject: [PATCH] std.fmt: remove placeholders from binary --- lib/std/fmt.zig | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index c8f5103626..9e7cf28eac 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -99,7 +99,8 @@ pub fn format( @setEvalBranchQuota(2000000); comptime var arg_state: ArgState = .{ .args_len = fields_info.len }; comptime var i = 0; - inline while (i < fmt.len) { + comptime var literal: []const u8 = ""; + inline while (true) { const start_index = i; inline while (i < fmt.len) : (i += 1) { @@ -121,14 +122,17 @@ pub fn format( i += 2; } - // Write out the literal - if (start_index != end_index) { - try writer.writeAll(fmt[start_index..end_index]); - } + literal = literal ++ fmt[start_index..end_index]; // We've already skipped the other brace, restart the loop if (unescape_brace) continue; + // Write out the literal + if (literal.len != 0) { + try writer.writeAll(literal); + literal = ""; + } + if (i >= fmt.len) break; if (fmt[i] == '}') {