Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project panel: Improve performance in worktrees with lots of files. (#12980)
Piotr Osiewiczeb7b5a7131fc
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex e29616fa379..4749d45a2ee 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -1792,6 +1792,10 @@ impl ProjectPanel {.unwrap_or(&[]);let entry_range = range.start.saturating_sub(ix)..end_ix - ix;+ let entries = visible_worktree_entries+ .iter()+ .map(|e| (e.path.clone()))+ .collect();for entry in visible_worktree_entries[entry_range].iter() {let status = git_status_setting.then(|| entry.git_status).flatten();let is_expanded = expanded_entry_ids.binary_search(&entry.id).is_ok();@@ -1812,10 +1816,8 @@ impl ProjectPanel {}};- let (depth, difference) = ProjectPanel::calculate_depth_and_difference(- entry,- visible_worktree_entries,- );+ let (depth, difference) =+ ProjectPanel::calculate_depth_and_difference(entry, &entries);let filename = match difference {diff if diff > 1 => entry@@ -1888,32 +1890,21 @@ impl ProjectPanel {fn calculate_depth_and_difference(entry: &Entry,- visible_worktree_entries: &Vec<Entry>,+ visible_worktree_entries: &HashSet<Arc<Path>>,) -> (usize, usize) {- let visible_worktree_paths: HashSet<Arc<Path>> = visible_worktree_entries- .iter()- .map(|e| e.path.clone())- .collect();-let (depth, difference) = entry.path.ancestors().skip(1) // Skip the entry itself.find_map(|ancestor| {- if visible_worktree_paths.contains(ancestor) {- let parent_entry = visible_worktree_entries- .iter()- .find(|&e| &*e.path == ancestor)- .unwrap();-+ if let Some(parent_entry) = visible_worktree_entries.get(ancestor) {let entry_path_components_count = entry.path.components().count();- let parent_path_components_count = parent_entry.path.components().count();+ let parent_path_components_count = parent_entry.components().count();let difference = entry_path_components_count - parent_path_components_count;let depth = parent_entry- .path.ancestors().skip(1)- .filter(|ancestor| visible_worktree_paths.contains(*ancestor))+ .filter(|ancestor| visible_worktree_entries.contains(*ancestor)).count();Some((depth + 1, difference))} else {