From 433d30e4c2519c673cb99876cba3357cb193ca9b Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Thu, 23 Apr 2026 18:25:24 +0800 Subject: [PATCH] gpui: Avoid redundant SharedString allocations in ShapedLine::split_at (#54583) Build split text directly from Arc slices instead of allocating intermediate Strings. Reuse the original SharedString for full-line splits, return a static empty string for empty sides, and add a regression test covering boundary splits. Release Notes: - N/A --------- Signed-off-by: Xiaobo Liu --- crates/gpui/src/text_system/line.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs index 9c6ffdbe3f..437ef48cb1 100644 --- a/crates/gpui/src/text_system/line.rs +++ b/crates/gpui/src/text_system/line.rs @@ -208,8 +208,16 @@ impl ShapedLine { } // Split text - let left_text = SharedString::new(self.text[..byte_index].to_string()); - let right_text = SharedString::new(self.text[byte_index..].to_string()); + let left_text = if byte_index == self.text.len() { + self.text.clone() + } else { + SharedString::new(&self.text[..byte_index]) + }; + let right_text = if byte_index == 0 { + self.text.clone() + } else { + SharedString::new(&self.text[byte_index..]) + }; let left_width = x_offset; let right_width = self.layout.width - left_width;