gpui: Avoid redundant SharedString allocations in ShapedLine::split_at (#54583)
Build split text directly from Arc<str> 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 <cppcoffee@gmail.com>
This commit is contained in:
1 parent
5896b767bf
commit
433d30e4c2
1 file changed
+10
-2
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user