Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project search: Reduce clones and allocations (#31133)
Remco Smitsdce22a965e99
diff --git a/crates/project/src/project.rs b/crates/project/src/project.rsindex 0d6c1b463c3..e319db10c3d 100644--- a/crates/project/src/project.rs+++ b/crates/project/src/project.rs@@ -3662,9 +3662,8 @@ impl Project {// ranges in the buffer matched by the query.let mut chunks = pin!(chunks);'outer: while let Some(matching_buffer_chunk) = chunks.next().await {- let mut chunk_results = Vec::new();+ let mut chunk_results = Vec::with_capacity(matching_buffer_chunk.len());for buffer in matching_buffer_chunk {- let buffer = buffer.clone();let query = query.clone();let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;chunk_results.push(cx.background_spawn(async move {diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rsindex 31e00b9ea7e..bbf61559b6d 100644--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@ -324,24 +324,24 @@ impl ProjectSearch {}}- let excerpts = project_search- .update(cx, |project_search, _| project_search.excerpts.clone())- .ok()?;- let mut new_ranges = excerpts- .update(cx, |excerpts, cx| {- buffers_with_ranges- .into_iter()- .map(|(buffer, ranges)| {- excerpts.set_anchored_excerpts_for_path(- buffer,- ranges,- editor::DEFAULT_MULTIBUFFER_CONTEXT,- cx,- )- })- .collect::<FuturesOrdered<_>>()+ let mut new_ranges = project_search+ .update(cx, |project_search, cx| {+ project_search.excerpts.update(cx, |excerpts, cx| {+ buffers_with_ranges+ .into_iter()+ .map(|(buffer, ranges)| {+ excerpts.set_anchored_excerpts_for_path(+ buffer,+ ranges,+ editor::DEFAULT_MULTIBUFFER_CONTEXT,+ cx,+ )+ })+ .collect::<FuturesOrdered<_>>()+ })}).ok()?;+while let Some(new_ranges) = new_ranges.next().await {project_search.update(cx, |project_search, _| {