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: Remove redundant allocation when merging highlight ranges (#57034)

Xiaobo Liubfe914beec96
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index bca778b79be..e04161b6c8a 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -3682,7 +3682,7 @@ impl EditorElement {
fn bg_segments_per_row(
rows: Range<DisplayRow>,
selections: &[(PlayerColor, Vec<SelectionLayout>)],
- highlight_ranges: &[(Range<DisplayPoint>, Hsla)],
+ highlight_ranges: impl IntoIterator<Item = (Range<DisplayPoint>, Hsla)>,
base_background: Hsla,
) -> Vec<Vec<(Range<DisplayPoint>, Hsla)>> {
if rows.start >= rows.end {
@@ -3692,7 +3692,7 @@ impl EditorElement {
// We don't actually know what color is behind this editor.
return Vec::new();
}
- let highlight_iter = highlight_ranges.iter().cloned();
+ let highlight_iter = highlight_ranges.into_iter();
let selection_iter = selections.iter().flat_map(|(player_color, layouts)| {
let color = player_color.selection;
layouts.iter().filter_map(move |selection_layout| {
@@ -10410,20 +10410,14 @@ impl Element for EditorElement {
cx,
);
- let merged_highlighted_ranges =
- if let Some((_, colors)) = document_colors.as_ref() {
- &highlighted_ranges
- .clone()
- .into_iter()
- .chain(colors.clone())
- .collect()
- } else {
- &highlighted_ranges
- };
let bg_segments_per_row = Self::bg_segments_per_row(
start_row..end_row,
&selections,
- &merged_highlighted_ranges,
+ highlighted_ranges.iter().cloned().chain(
+ document_colors
+ .iter()
+ .flat_map(|(_, colors)| colors.iter().cloned()),
+ ),
self.style.background,
);
@@ -13849,7 +13843,7 @@ mod tests {
let result = EditorElement::bg_segments_per_row(
DisplayRow(0)..DisplayRow(5),
&selections,
- &[],
+ [].into_iter(),
base_bg,
);
@@ -13898,7 +13892,7 @@ mod tests {
let result = EditorElement::bg_segments_per_row(
DisplayRow(0)..DisplayRow(4),
&selections,
- &[],
+ [].into_iter(),
base_bg,
);