mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 04:23:30 +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))]
|
#[cfg(not(no_global_oom_handling))]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[inline]
|
||||||
pub fn format(args: Arguments<'_>) -> string::String {
|
pub fn format(args: Arguments<'_>) -> string::String {
|
||||||
let capacity = args.estimated_capacity();
|
#[cold]
|
||||||
let mut output = string::String::with_capacity(capacity);
|
fn format_cold(args: Arguments<'_>) -> string::String {
|
||||||
output.write_fmt(args).expect("a formatting trait implementation returned an error");
|
let capacity = args.estimated_capacity();
|
||||||
output
|
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