Reduce string allocations in Editor::insert
Co-authored-by: Nathan Sobo <nathan@zed.dev> Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
parent
920601cb94
commit
2c2ca1bfbd
1 changed files with 4 additions and 1 deletions
|
@ -1945,6 +1945,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
|
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
|
||||||
|
let text: Arc<str> = text.into();
|
||||||
self.transact(cx, |this, cx| {
|
self.transact(cx, |this, cx| {
|
||||||
let old_selections = this.local_selections::<usize>(cx);
|
let old_selections = this.local_selections::<usize>(cx);
|
||||||
let selection_anchors = this.buffer.update(cx, |buffer, cx| {
|
let selection_anchors = this.buffer.update(cx, |buffer, cx| {
|
||||||
|
@ -1956,7 +1957,9 @@ impl Editor {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
buffer.edit_with_autoindent(
|
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,
|
cx,
|
||||||
);
|
);
|
||||||
anchors
|
anchors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue