Preallocate vector for MultiBuffer::excerpt_ids (#49381)

This saves some time spent reallocating inside `Editor::on_buffer_event`
for large multibuffers.

Release Notes:

- N/A
This commit is contained in:
Cole Miller authored and GitHub committed 2026-02-17 17:04:55 -05:00
1 parent 3b438222ef
commit 90e1abd5bf
1 file changed
+7 -6
+7 -6
View File
@@ -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;
}
}