Skip to content

Commit

Permalink
Call write_fmt directly to format an Arguments value.
Browse files Browse the repository at this point in the history
It's just as convenient, but it's much faster. Using write! requires an
extra call to fmt::write and a extra dynamically dispatched call to
Arguments' Display format function.
  • Loading branch information
rprichard committed Apr 17, 2015
1 parent 8f209d5 commit 317eac3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,6 @@ use string;
#[stable(feature = "rust1", since = "1.0.0")]
pub fn format(args: Arguments) -> string::String {
let mut output = string::String::new();
let _ = write!(&mut output, "{}", args);
let _ = output.write_fmt(args);
output
}
2 changes: 1 addition & 1 deletion src/libstd/rt/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, u32)) ->
// below).

let mut s = String::new();
let _ = write!(&mut s, "{}", msg);
let _ = s.write_fmt(msg);
begin_unwind_inner(Box::new(s), file_line)
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) ||
cfg!(rtassert);

pub fn dumb_print(args: fmt::Arguments) {
let _ = write!(&mut Stderr::new(), "{}", args);
let _ = Stderr::new().write_fmt(args);
}

pub fn abort(args: fmt::Arguments) -> ! {
Expand Down

0 comments on commit 317eac3

Please sign in to comment.