mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 00:53:48 +00:00
improve format impl for literals
This commit is contained in:
parent
9d1aeaeb82
commit
3f404bfa86
@ -604,9 +604,15 @@ use crate::string;
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn format(args: Arguments<'_>) -> string::String {
|
||||
#[cold]
|
||||
fn format_cold(args: Arguments<'_>) -> string::String {
|
||||
let capacity = args.estimated_capacity();
|
||||
let mut output = string::String::with_capacity(capacity);
|
||||
output.write_fmt(args).expect("a formatting trait implementation returned an error");
|
||||
output
|
||||
}
|
||||
|
||||
args.as_str().map_or_else(|| format_cold(args), crate::borrow::ToOwned::to_owned)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user