From 2c2ca1bfbd7caddf7297fe342e7c51a507bfeae9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 29 Apr 2022 10:07:21 -0700 Subject: [PATCH] Reduce string allocations in Editor::insert Co-authored-by: Nathan Sobo Co-authored-by: Keith Simmons --- crates/editor/src/editor.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 8a7df58acd..e5aad0e7d1 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1945,6 +1945,7 @@ impl Editor { } pub fn insert(&mut self, text: &str, cx: &mut ViewContext) { + let text: Arc = text.into(); self.transact(cx, |this, cx| { let old_selections = this.local_selections::(cx); let selection_anchors = this.buffer.update(cx, |buffer, cx| { @@ -1956,7 +1957,9 @@ impl Editor { .collect::>() }; buffer.edit_with_autoindent( - old_selections.iter().map(|s| (s.start..s.end, text)), + old_selections + .iter() + .map(|s| (s.start..s.end, text.clone())), cx, ); anchors