Skip to content

Commit e0991b7

Browse files
authored
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.
2 parents 57172a0 + fd80ab7 commit e0991b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/alloc/src/string.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,15 @@ impl ToString for String {
26232623
}
26242624
}
26252625

2626+
#[cfg(not(no_global_oom_handling))]
2627+
#[stable(feature = "fmt_arguments_to_string_specialization", since = "CURRENT_RUSTC_VERSION")]
2628+
impl ToString for fmt::Arguments<'_> {
2629+
#[inline]
2630+
fn to_string(&self) -> String {
2631+
crate::fmt::format(*self)
2632+
}
2633+
}
2634+
26262635
#[stable(feature = "rust1", since = "1.0.0")]
26272636
impl AsRef<str> for String {
26282637
#[inline]

0 commit comments

Comments
 (0)