Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Avoid redundant SharedString allocations in ShapedLine::split_at (#54583)

Xiaobo Liu43d6ab5386ef
diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs
index 9c6ffdbe3f6..437ef48cb17 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;