Rollup merge of #111168 - DaniPopes:arguments-to-string, r=Mark-Simulacrum

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.
This commit is contained in:
Dylan DPC 2023-05-18 10:52:34 +05:30 committed by GitHub
commit e0991b7bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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]