Skip to content

Commit

Permalink
Rollup merge of #111168 - DaniPopes:arguments-to-string, r=Mark-Simul…
Browse files Browse the repository at this point in the history
…acrum

Specialize ToString implementation for fmt::Arguments

Generates far fewer instructions by formatting into a String with `fmt::format` directly instead of going through the `fmt::Display` impl. This change is insta-stable.
  • Loading branch information
Dylan-DPC authored May 18, 2023
2 parents 57172a0 + fd80ab7 commit e0991b7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,15 @@ impl ToString for String {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "fmt_arguments_to_string_specialization", since = "CURRENT_RUSTC_VERSION")]
impl ToString for fmt::Arguments<'_> {
#[inline]
fn to_string(&self) -> String {
crate::fmt::format(*self)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<str> for String {
#[inline]
Expand Down

0 comments on commit e0991b7

Please sign in to comment.