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.

editor: Improve performance of `create_highlight_endpoints` (#44521)

Lukas Wirthb1333b53ad65
diff --git a/crates/editor/src/display_map/custom_highlights.rs b/crates/editor/src/display_map/custom_highlights.rs
index c9202280bf9..1ece2493e32 100644
--- a/crates/editor/src/display_map/custom_highlights.rs
+++ b/crates/editor/src/display_map/custom_highlights.rs
@@ -79,12 +79,15 @@ fn create_highlight_endpoints(
let start_ix = ranges
.binary_search_by(|probe| probe.end.cmp(&start, buffer).then(cmp::Ordering::Less))
.unwrap_or_else(|i| i);
+ let end_ix = ranges[start_ix..]
+ .binary_search_by(|probe| {
+ probe.start.cmp(&end, buffer).then(cmp::Ordering::Greater)
+ })
+ .unwrap_or_else(|i| i);
- for range in &ranges[start_ix..] {
- if range.start.cmp(&end, buffer).is_ge() {
- break;
- }
+ highlight_endpoints.reserve(2 * end_ix);
+ for range in &ranges[start_ix..][..end_ix] {
let start = range.start.to_offset(buffer);
let end = range.end.to_offset(buffer);
if start == end {