Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Preallocate vector for `MultiBuffer::excerpt_ids` (#49381)
Cole Miller90e1abd5bf75
diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rsindex 3d65588bceb..75399e61307 100644--- a/crates/multi_buffer/src/multi_buffer.rs+++ b/crates/multi_buffer/src/multi_buffer.rs@@ -799,6 +799,7 @@ pub struct ExcerptSummary {excerpt_locator: Locator,widest_line_number: u32,text: MBTextSummary,+ count: usize,}#[derive(Debug, Clone)]@@ -2046,12 +2047,10 @@ impl MultiBuffer {}pub fn excerpt_ids(&self) -> Vec<ExcerptId> {- self.snapshot- .borrow()- .excerpts- .iter()- .map(|entry| entry.id)- .collect()+ let snapshot = self.snapshot.borrow();+ let mut ids = Vec::with_capacity(snapshot.excerpts.summary().count);+ ids.extend(snapshot.excerpts.iter().map(|entry| entry.id));+ ids}pub fn excerpt_containing(@@ -7746,6 +7745,7 @@ impl sum_tree::Item for Excerpt {excerpt_locator: self.locator.clone(),widest_line_number: self.max_buffer_row,text: text.into(),+ count: 1,}}}@@ -7840,6 +7840,7 @@ impl sum_tree::ContextLessSummary for ExcerptSummary {self.excerpt_locator = summary.excerpt_locator.clone();self.text += summary.text;self.widest_line_number = cmp::max(self.widest_line_number, summary.widest_line_number);+ self.count += summary.count;}}