From d90770c673bd19afcd88c2b35ccf4e711f02a18d Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 4 Nov 2024 17:21:09 +0200 Subject: [PATCH] Actually reuse previous search entries (#20171) Release Notes: - Improved outline panel performance during large project searches --- crates/outline_panel/src/outline_panel.rs | 36 +++++++++-------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index a7708ec08fd4056c5ac249c59b384fab1d0c0645..86816e9adbc05ca7aa430ea4c453f1de8c6d46aa 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -3499,35 +3499,27 @@ impl OutlinePanel { || related_excerpts.contains(&match_range.end.excerpt_id) }); - let previous_search_matches = state - .entries + let previous_search_matches = self + .cached_entries .iter() - .skip_while(|entry| { - if let PanelEntry::Fs(entry) = &entry.entry { - entry == &parent_entry + .filter_map(|entry| { + if let PanelEntry::Search(search_entry) = &entry.entry { + Some(search_entry) } else { - true + None } }) - .take_while(|entry| matches!(entry.entry, PanelEntry::Search(_))) - .fold( - HashMap::default(), - |mut previous_matches, previous_entry| match &previous_entry.entry { - PanelEntry::Search(search_entry) => { - previous_matches.insert( - (search_entry.kind, &search_entry.match_range), - &search_entry.render_data, - ); - previous_matches - } - _ => previous_matches, - }, - ); + .filter(|search_entry| search_entry.kind == kind) + .filter(|search_entry| { + related_excerpts.contains(&search_entry.match_range.start.excerpt_id) + || related_excerpts.contains(&search_entry.match_range.end.excerpt_id) + }) + .map(|search_entry| (&search_entry.match_range, &search_entry.render_data)) + .collect::>(); let new_search_entries = new_search_matches .map(|(match_range, search_data)| { - let previous_search_data = - previous_search_matches.get(&(kind, match_range)).copied(); + let previous_search_data = previous_search_matches.get(&match_range).copied(); let render_data = search_data .get() .or(previous_search_data)