diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 4e095fbc232..1c9f660dceb 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -263,7 +263,7 @@ impl Element for &'static str { cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState) { let state = TextLayout::default(); - let layout_id = state.layout(SharedString::from(*self), None, window, cx); + let layout_id = state.layout(SharedString::new_static(self), None, window, cx); (layout_id, state) } diff --git a/crates/gpui_shared_string/gpui_shared_string.rs b/crates/gpui_shared_string/gpui_shared_string.rs index bdb9e27453c..442851e822d 100644 --- a/crates/gpui_shared_string/gpui_shared_string.rs +++ b/crates/gpui_shared_string/gpui_shared_string.rs @@ -11,9 +11,22 @@ use smol_str::SmolStr; /// A shared string is an immutable string that can be cheaply cloned in GPUI /// tasks. Essentially an abstraction over an `Arc` and `&'static str`, /// currently backed by a [`SmolStr`]. -#[derive(Eq, PartialEq, PartialOrd, Ord, Hash, Clone)] +#[derive(Eq, PartialOrd, Ord, Clone)] pub struct SharedString(SmolStr); +impl PartialEq for SharedString { + fn eq(&self, other: &Self) -> bool { + let (this, other_str) = (self.as_str(), other.as_str()); + (this.as_ptr() == other_str.as_ptr() && this.len() == other_str.len()) || self.0 == other.0 + } +} + +impl std::hash::Hash for SharedString { + fn hash(&self, state: &mut H) { + self.0.hash(state); + } +} + impl std::ops::Deref for SharedString { type Target = str;