Closed
Description
The ToString::to_string()
implementation for bool
generates over 700 lines of LLVM IR and 500 lines of AArch64 assembly!
Using format!
with Display
or Debug
is also unnecessarily inefficient.
https://godbolt.org/z/3M4jGYE9d
// Worst
pub fn to_string(b: bool) -> String {
b.to_string()
}
// Better
pub fn format_display(b: bool) -> String {
format!("{b}")
}
pub fn format_debug(b: bool) -> String {
format!("{b:?}")
}
// Best
pub fn if_then_else(b: bool) -> String {
if b {
"true".into()
} else {
"false".into()
}
}
Version
rustc 1.68.0-nightly (ee0412d1e 2023-01-07)
binary: rustc
commit-hash: ee0412d1ef81efcfabe7f66cd21476ca85d618b1
commit-date: 2023-01-07
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6