search: Remove intermediate allocation (#45633)

Release Notes:

- N/A

---------

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
This commit is contained in:
Marco Mihai Condrache
2025-12-25 20:29:17 +01:00
committed by GitHub
parent ca47822667
commit f03987fb68

View File

@@ -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>(