Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project_panel: Reduce cloning when rendering entries (#56993)
Xiaobo Liu56816c033336
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 9c23e7ff8cf..7b1072849c0 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -5369,6 +5369,7 @@ impl ProjectPanel {&self,entry_id: ProjectEntryId,details: EntryDetails,+ marked_selections: Arc<[SelectedEntry]>,window: &mut Window,cx: &mut Context<Self>,) -> Stateful<Div> {@@ -5405,24 +5406,12 @@ impl ProjectPanel {let diagnostic_count = details.diagnostic_count;let item_colors = get_item_color(is_sticky, cx);- let canonical_path = details- .canonical_path- .as_ref()- .map(|f| f.to_string_lossy().into_owned());+ let canonical_path = details.canonical_path.clone();let path_style = self.project.read(cx).path_style(cx);let path = details.path.clone();- let path_for_external_paths = path.clone();- let path_for_dragged_selection = path.clone();let depth = details.depth;let worktree_id = details.worktree_id;- let dragged_selection = DraggedSelection {- active_selection: SelectedEntry {- worktree_id: selection.worktree_id,- entry_id: selection.entry_id,- },- marked_selections: Arc::from(self.marked_entries.clone()),- };let bg_color = if is_marked {item_colors.marked@@ -5530,6 +5519,13 @@ impl ProjectPanel {},).when(settings.drag_and_drop, |this| {+ let path_for_external_paths = path.clone();+ let path_for_dragged_selection = path.clone();+ let dragged_selection = DraggedSelection {+ active_selection: selection,+ marked_selections: marked_selections.clone(),+ };+this.on_drag_move::<ExternalPaths>(cx.listener(move |this, event: &DragMoveEvent<ExternalPaths>, _, cx| {let is_current_target =@@ -5855,7 +5851,7 @@ impl ProjectPanel {.id("symlink_icon").tooltip(move |_window, cx| {Tooltip::with_meta(- path.to_string(),+ path.to_string_lossy().into_owned(),None,"Symbolic Link",cx,@@ -6567,6 +6563,7 @@ impl ProjectPanel {// already checked if non empty abovelet last_item_index = sticky_parents.len() - 1;+ let marked_selections: Arc<[SelectedEntry]> = Arc::from(self.marked_entries.clone());sticky_parents.iter().enumerate()@@ -6588,24 +6585,30 @@ impl ProjectPanel {window,cx,);- self.render_entry(entry.id, details, window, cx)- .when(index == last_item_index, |this| {- let shadow_color_top = hsla(0.0, 0.0, 0.0, 0.1);- let shadow_color_bottom = hsla(0.0, 0.0, 0.0, 0.);- let sticky_shadow = div()- .absolute()- .left_0()- .bottom_neg_1p5()- .h_1p5()- .w_full()- .bg(linear_gradient(- 0.,- linear_color_stop(shadow_color_top, 1.),- linear_color_stop(shadow_color_bottom, 0.),- ));- this.child(sticky_shadow)- })- .into_any()+ self.render_entry(+ entry.id,+ details,+ Arc::clone(&marked_selections),+ window,+ cx,+ )+ .when(index == last_item_index, |this| {+ let shadow_color_top = hsla(0.0, 0.0, 0.0, 0.1);+ let shadow_color_bottom = hsla(0.0, 0.0, 0.0, 0.);+ let sticky_shadow = div()+ .absolute()+ .left_0()+ .bottom_neg_1p5()+ .h_1p5()+ .w_full()+ .bg(linear_gradient(+ 0.,+ linear_color_stop(shadow_color_top, 1.),+ linear_color_stop(shadow_color_bottom, 0.),+ ));+ this.child(sticky_shadow)+ })+ .into_any()}).collect()}@@ -6815,12 +6818,20 @@ impl Render for ProjectPanel {cx.processor(|this, range: Range<usize>, window, cx| {this.rendered_entries_len = range.end - range.start;let mut items = Vec::with_capacity(this.rendered_entries_len);+ let marked_selections: Arc<[SelectedEntry]> =+ Arc::from(this.marked_entries.clone());this.for_each_visible_entry(range,window,cx,&mut |id, details, window, cx| {- items.push(this.render_entry(id, details, window, cx));+ items.push(this.render_entry(+ id,+ details,+ Arc::clone(&marked_selections),+ window,+ cx,+ ));},);items