search: Improve performance of replace_all (#13654)

Previously replace_all amounted to what could be achieved by repeatedly
mashing "Replace" button, which had a bunch of overhead related to
buffer state syncing. This commit gets rid of the automated button
mashing, processing all of the replacements in one go.

Fixes #13455



Release Notes:

- Improved performance of "replace all" in buffer search and project
search
This commit is contained in:
Piotr Osiewicz 2024-06-28 19:06:44 +02:00 committed by GitHub
parent b616f9c27f
commit 0761383752
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 6 deletions

View file

@ -71,6 +71,16 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
fn activate_match(&mut self, index: usize, matches: &[Self::Match], cx: &mut ViewContext<Self>);
fn select_matches(&mut self, matches: &[Self::Match], cx: &mut ViewContext<Self>);
fn replace(&mut self, _: &Self::Match, _: &SearchQuery, _: &mut ViewContext<Self>);
fn replace_all(
&mut self,
matches: &mut dyn Iterator<Item = &Self::Match>,
query: &SearchQuery,
cx: &mut ViewContext<Self>,
) {
for item in matches {
self.replace(item, query, cx);
}
}
fn match_index_for_direction(
&mut self,
matches: &[Self::Match],
@ -123,6 +133,12 @@ pub trait SearchableItemHandle: ItemHandle {
_: &SearchQuery,
_: &mut WindowContext,
);
fn replace_all(
&self,
matches: &mut dyn Iterator<Item = any_vec::element::ElementRef<'_, dyn Send>>,
query: &SearchQuery,
cx: &mut WindowContext,
);
fn match_index_for_direction(
&self,
matches: &AnyVec<dyn Send>,
@ -241,6 +257,17 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
self.update(cx, |this, cx| this.replace(mat, query, cx))
}
fn replace_all(
&self,
matches: &mut dyn Iterator<Item = any_vec::element::ElementRef<'_, dyn Send>>,
query: &SearchQuery,
cx: &mut WindowContext,
) {
self.update(cx, |this, cx| {
this.replace_all(&mut matches.map(|m| m.downcast_ref().unwrap()), query, cx);
})
}
fn search_bar_visibility_changed(&self, visible: bool, cx: &mut WindowContext) {
self.update(cx, |this, cx| {
this.search_bar_visibility_changed(visible, cx)