Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
search: Remove intermediate allocation (#45633)
Marco Mihai Condrachef03987fb6822
diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rsindex e0bbf58ce6f..5fbb6788f2d 100644--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@ -1531,14 +1531,20 @@ impl ProjectSearchView {fn update_match_index(&mut self, cx: &mut Context<Self>) {let results_editor = self.results_editor.read(cx);- let match_ranges = self.entity.read(cx).match_ranges.clone();- let new_index = active_match_index(- Direction::Next,- &match_ranges,- &results_editor.selections.newest_anchor().head(),- &results_editor.buffer().read(cx).snapshot(cx),- );- self.highlight_matches(&match_ranges, new_index, cx);+ let newest_anchor = results_editor.selections.newest_anchor().head();+ let buffer_snapshot = results_editor.buffer().read(cx).snapshot(cx);+ let new_index = self.entity.update(cx, |this, cx| {+ let new_index = active_match_index(+ Direction::Next,+ &this.match_ranges,+ &newest_anchor,+ &buffer_snapshot,+ );++ self.highlight_matches(&this.match_ranges, new_index, cx);+ new_index+ });+if self.active_match_index != new_index {self.active_match_index = new_index;cx.notify();@@ -1550,7 +1556,7 @@ impl ProjectSearchView {&self,match_ranges: &[Range<Anchor>],active_index: Option<usize>,- cx: &mut Context<Self>,+ cx: &mut App,) {self.results_editor.update(cx, |editor, cx| {editor.highlight_background::<Self>(