Skip to content

fmt: Skip calling write_str for empty strings #31966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,15 +792,19 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
None => {
// We can use default formatting parameters for all arguments.
for (arg, piece) in args.args.iter().zip(pieces.by_ref()) {
try!(formatter.buf.write_str(*piece));
if !piece.is_empty() {
try!(formatter.buf.write_str(*piece));
}
try!((arg.formatter)(arg.value, &mut formatter));
}
}
Some(fmt) => {
// Every spec has a corresponding argument that is preceded by
// a string piece.
for (arg, piece) in fmt.iter().zip(pieces.by_ref()) {
try!(formatter.buf.write_str(*piece));
if !piece.is_empty() {
try!(formatter.buf.write_str(*piece));
}
try!(formatter.run(arg));
}
}
Expand All @@ -809,7 +813,9 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
// There can be only one trailing string piece left.
match pieces.next() {
Some(piece) => {
try!(formatter.buf.write_str(*piece));
if !piece.is_empty() {
try!(formatter.buf.write_str(*piece));
}
}
None => {}
}
Expand Down