From 753289706af8827c36028b00e8d7732bb0b0c37c Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 21 Mar 2017 15:00:33 +0100 Subject: [PATCH] Don't call `fmt::Write::write_str` for statically empty strings This means that `writeln!(something, "{}{}", s1, s2)` no longer calls `write_str` two times with empty strings (before each substitution). See #31966 for an earlier attempt. --- src/libsyntax_ext/format.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index d2afa08cadaf4..63a4268df29e7 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -751,8 +751,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, let mut arg_index_consumed = vec![0usize; cx.arg_index_map.len()]; for piece in pieces { if let Some(piece) = cx.trans_piece(&piece, &mut arg_index_consumed) { - let s = cx.trans_literal_string(); - cx.str_pieces.push(s); + if !cx.literal.is_empty() { + let s = cx.trans_literal_string(); + cx.str_pieces.push(s); + } cx.pieces.push(piece); } }