Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/smol_str/src/lib.rs')
| -rw-r--r-- | lib/smol_str/src/lib.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs index 31695b8117..0d1f01a32b 100644 --- a/lib/smol_str/src/lib.rs +++ b/lib/smol_str/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] +#![debugger_visualizer(gdb_script_file = "gdb_smolstr_printer.py")] extern crate alloc; @@ -104,11 +105,19 @@ impl SmolStr { impl Clone for SmolStr { #[inline] fn clone(&self) -> Self { - if !self.is_heap_allocated() { - // SAFETY: We verified that the payload of `Repr` is a POD - return unsafe { core::ptr::read(self as *const SmolStr) }; + // hint for faster inline / slower heap clones + #[cold] + #[inline(never)] + fn cold_clone(v: &SmolStr) -> SmolStr { + SmolStr(v.0.clone()) } - Self(self.0.clone()) + + if self.is_heap_allocated() { + return cold_clone(self); + } + + // SAFETY: We verified that the payload of `Repr` is a POD + unsafe { core::ptr::read(self as *const SmolStr) } } } |