Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

multi_buffer: Improve lookup performance for `MultiBufferSnapshot::excerpt` (#49986)

Lukas Wirth3cf7cb52655b
diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs
index 22142c2e28b..34d32f48194 100644
--- a/crates/multi_buffer/src/multi_buffer.rs
+++ b/crates/multi_buffer/src/multi_buffer.rs
@@ -7034,16 +7034,16 @@ impl MultiBufferSnapshot {
/// afterwards.
fn excerpt(&self, excerpt_id: ExcerptId) -> Option<&Excerpt> {
let excerpt_id = self.latest_excerpt_id(excerpt_id);
- let mut cursor = self.excerpts.cursor::<Option<&Locator>>(());
let locator = self.excerpt_locator_for_id(excerpt_id);
- cursor.seek(&Some(locator), Bias::Left);
- if let Some(excerpt) = cursor.item()
+ let (_, _, item) =
+ self.excerpts
+ .find::<Option<&Locator>, _>((), &Some(locator), Bias::Left);
+ if let Some(excerpt) = item
&& excerpt.id == excerpt_id
{
return Some(excerpt);
- } else if cursor.item().is_none() && excerpt_id == ExcerptId::max() {
- cursor.prev();
- return cursor.item();
+ } else if item.is_none() && excerpt_id == ExcerptId::max() {
+ return self.excerpts.last();
}
None
}