Skip to content

Commit 7532897

Browse files
committed
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 rust-lang#31966 for an earlier attempt.
1 parent 134c4a0 commit 7532897

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libsyntax_ext/format.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
751751
let mut arg_index_consumed = vec![0usize; cx.arg_index_map.len()];
752752
for piece in pieces {
753753
if let Some(piece) = cx.trans_piece(&piece, &mut arg_index_consumed) {
754-
let s = cx.trans_literal_string();
755-
cx.str_pieces.push(s);
754+
if !cx.literal.is_empty() {
755+
let s = cx.trans_literal_string();
756+
cx.str_pieces.push(s);
757+
}
756758
cx.pieces.push(piece);
757759
}
758760
}

0 commit comments

Comments
 (0)