From f03987fb68224e3b7fb993ce2ffaf364836a003c Mon Sep 17 00:00:00 2001 From: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Date: Thu, 25 Dec 2025 20:29:17 +0100 Subject: [PATCH] search: Remove intermediate allocation (#45633) Release Notes: - N/A --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> --- crates/search/src/project_search.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index e0bbf58ce6f1d0c752914bbbfa6fcdf70ea30175..5fbb6788f2d30a4649fd9b5a6f7436488c051b34 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) { 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], active_index: Option, - cx: &mut Context, + cx: &mut App, ) { self.results_editor.update(cx, |editor, cx| { editor.highlight_background::(