Actually reuse previous search entries (#20171)

Release Notes:

- Improved outline panel performance during large project searches
This commit is contained in:
Kirill Bulatov 2024-11-04 17:21:09 +02:00 committed by GitHub
parent 6316151a83
commit d90770c673
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3499,35 +3499,27 @@ impl OutlinePanel {
|| related_excerpts.contains(&match_range.end.excerpt_id) || related_excerpts.contains(&match_range.end.excerpt_id)
}); });
let previous_search_matches = state let previous_search_matches = self
.entries .cached_entries
.iter() .iter()
.skip_while(|entry| { .filter_map(|entry| {
if let PanelEntry::Fs(entry) = &entry.entry { if let PanelEntry::Search(search_entry) = &entry.entry {
entry == &parent_entry Some(search_entry)
} else { } else {
true None
} }
}) })
.take_while(|entry| matches!(entry.entry, PanelEntry::Search(_))) .filter(|search_entry| search_entry.kind == kind)
.fold( .filter(|search_entry| {
HashMap::default(), related_excerpts.contains(&search_entry.match_range.start.excerpt_id)
|mut previous_matches, previous_entry| match &previous_entry.entry { || related_excerpts.contains(&search_entry.match_range.end.excerpt_id)
PanelEntry::Search(search_entry) => { })
previous_matches.insert( .map(|search_entry| (&search_entry.match_range, &search_entry.render_data))
(search_entry.kind, &search_entry.match_range), .collect::<HashMap<_, _>>();
&search_entry.render_data,
);
previous_matches
}
_ => previous_matches,
},
);
let new_search_entries = new_search_matches let new_search_entries = new_search_matches
.map(|(match_range, search_data)| { .map(|(match_range, search_data)| {
let previous_search_data = let previous_search_data = previous_search_matches.get(&match_range).copied();
previous_search_matches.get(&(kind, match_range)).copied();
let render_data = search_data let render_data = search_data
.get() .get()
.or(previous_search_data) .or(previous_search_data)