Rollup merge of #106662 - Ezrashaw:specialize-bool-tostring, r=cuviper
specialize impl of `ToString` on `bool` Fixes #106611 Specialize `bool`s `ToString` impl by copying it from `Display`. This is a significant optimization as we avoid lots of dynamic dispatch. AFAIK, this doesn't require a API Change Proposal as this doesn't regress existing code and can be undone without regressing code.
This commit is contained in:
commit
feca61e5eb
1 changed files with 9 additions and 0 deletions
|
@ -2548,6 +2548,15 @@ impl ToString for char {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(no_global_oom_handling))]
|
||||||
|
#[stable(feature = "bool_to_string_specialization", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
impl ToString for bool {
|
||||||
|
#[inline]
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
String::from(if *self { "true" } else { "false" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(no_global_oom_handling))]
|
#[cfg(not(no_global_oom_handling))]
|
||||||
#[stable(feature = "u8_to_string_specialization", since = "1.54.0")]
|
#[stable(feature = "u8_to_string_specialization", since = "1.54.0")]
|
||||||
impl ToString for u8 {
|
impl ToString for u8 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue