chore: Clean up allocs around project panel (#15422)

Piotr Osiewicz created

A drive-by I did when looking at something else.

Release Notes:

- N/A

Change summary

crates/file_icons/src/file_icons.rs       | 14 +++++++-------
crates/project_panel/src/project_panel.rs |  6 +++---
crates/worktree/src/worktree.rs           | 16 ++++++++--------
3 files changed, 18 insertions(+), 18 deletions(-)

Detailed changes

crates/file_icons/src/file_icons.rs 🔗

@@ -1,14 +1,14 @@
-use std::{path::Path, str, sync::Arc};
+use std::{path::Path, str};
 
 use collections::HashMap;
 
-use gpui::{AppContext, AssetSource, Global};
+use gpui::{AppContext, AssetSource, Global, SharedString};
 use serde_derive::Deserialize;
 use util::{maybe, paths::PathExt};
 
 #[derive(Deserialize, Debug)]
 struct TypeConfig {
-    icon: Arc<str>,
+    icon: SharedString,
 }
 
 #[derive(Deserialize, Debug)]
@@ -48,7 +48,7 @@ impl FileIcons {
             })
     }
 
-    pub fn get_icon(path: &Path, cx: &AppContext) -> Option<Arc<str>> {
+    pub fn get_icon(path: &Path, cx: &AppContext) -> Option<SharedString> {
         let this = cx.try_global::<Self>()?;
 
         // FIXME: Associate a type with the languages and have the file's language
@@ -67,13 +67,13 @@ impl FileIcons {
         .or_else(|| this.get_type_icon("default"))
     }
 
-    pub fn get_type_icon(&self, typ: &str) -> Option<Arc<str>> {
+    pub fn get_type_icon(&self, typ: &str) -> Option<SharedString> {
         self.types
             .get(typ)
             .map(|type_config| type_config.icon.clone())
     }
 
-    pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Option<Arc<str>> {
+    pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
         let this = cx.try_global::<Self>()?;
 
         let key = if expanded {
@@ -85,7 +85,7 @@ impl FileIcons {
         this.get_type_icon(key)
     }
 
-    pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Option<Arc<str>> {
+    pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
         let this = cx.try_global::<Self>()?;
 
         let key = if expanded {

crates/project_panel/src/project_panel.rs 🔗

@@ -94,7 +94,7 @@ enum ClipboardEntry {
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub struct EntryDetails {
     filename: String,
-    icon: Option<Arc<str>>,
+    icon: Option<SharedString>,
     path: Arc<Path>,
     depth: usize,
     kind: EntryKind,
@@ -108,7 +108,7 @@ pub struct EntryDetails {
     git_status: Option<GitFileStatus>,
     is_private: bool,
     worktree_id: WorktreeId,
-    canonical_path: Option<PathBuf>,
+    canonical_path: Option<Box<Path>>,
 }
 
 #[derive(PartialEq, Clone, Default, Debug, Deserialize)]
@@ -2538,7 +2538,7 @@ impl Render for DraggedProjectEntryView {
                         .indent_level(self.details.depth)
                         .indent_step_size(px(settings.indent_size))
                         .child(if let Some(icon) = &self.details.icon {
-                            div().child(Icon::from_path(icon.to_string()))
+                            div().child(Icon::from_path(icon.clone()))
                         } else {
                             div()
                         })

crates/worktree/src/worktree.rs 🔗

@@ -3127,7 +3127,7 @@ pub struct Entry {
     pub inode: u64,
     pub mtime: Option<SystemTime>,
 
-    pub canonical_path: Option<PathBuf>,
+    pub canonical_path: Option<Box<Path>>,
     pub is_symlink: bool,
     /// Whether this entry is ignored by Git.
     ///
@@ -3186,7 +3186,7 @@ impl Entry {
         metadata: &fs::Metadata,
         next_entry_id: &AtomicUsize,
         root_char_bag: CharBag,
-        canonical_path: Option<PathBuf>,
+        canonical_path: Option<Box<Path>>,
     ) -> Self {
         Self {
             id: ProjectEntryId::new(next_entry_id),
@@ -3942,7 +3942,7 @@ impl BackgroundScanner {
                     child_entry.is_external = true;
                 }
 
-                child_entry.canonical_path = Some(canonical_path);
+                child_entry.canonical_path = Some(canonical_path.into());
             }
 
             if child_entry.is_dir() {
@@ -4073,21 +4073,21 @@ impl BackgroundScanner {
             }
         }
 
-        for (path, metadata) in relative_paths.iter().zip(metadata.iter()) {
+        for (path, metadata) in relative_paths.iter().zip(metadata.into_iter()) {
             let abs_path: Arc<Path> = root_abs_path.join(&path).into();
             match metadata {
                 Ok(Some((metadata, canonical_path))) => {
                     let ignore_stack = state
                         .snapshot
                         .ignore_stack_for_abs_path(&abs_path, metadata.is_dir);
-
+                    let is_external = !canonical_path.starts_with(&root_canonical_path);
                     let mut fs_entry = Entry::new(
                         path.clone(),
-                        metadata,
+                        &metadata,
                         self.next_entry_id.as_ref(),
                         state.snapshot.root_char_bag,
                         if metadata.is_symlink {
-                            Some(canonical_path.to_path_buf())
+                            Some(canonical_path.into())
                         } else {
                             None
                         },
@@ -4096,7 +4096,7 @@ impl BackgroundScanner {
                     let is_dir = fs_entry.is_dir();
                     fs_entry.is_ignored = ignore_stack.is_abs_path_ignored(&abs_path, is_dir);
 
-                    fs_entry.is_external = !canonical_path.starts_with(&root_canonical_path);
+                    fs_entry.is_external = is_external;
                     fs_entry.is_private = self.is_path_private(path);
 
                     if !is_dir && !fs_entry.is_ignored && !fs_entry.is_external {