chore: Clean up allocs around project panel (#15422)
A drive-by I did when looking at something else. Release Notes: - N/A
This commit is contained in:
parent
6af72ab53a
commit
c97d035eea
3 changed files with 18 additions and 18 deletions
|
@ -1,14 +1,14 @@
|
||||||
use std::{path::Path, str, sync::Arc};
|
use std::{path::Path, str};
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
|
||||||
use gpui::{AppContext, AssetSource, Global};
|
use gpui::{AppContext, AssetSource, Global, SharedString};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use util::{maybe, paths::PathExt};
|
use util::{maybe, paths::PathExt};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct TypeConfig {
|
struct TypeConfig {
|
||||||
icon: Arc<str>,
|
icon: SharedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[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>()?;
|
let this = cx.try_global::<Self>()?;
|
||||||
|
|
||||||
// FIXME: Associate a type with the languages and have the file's language
|
// 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"))
|
.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
|
self.types
|
||||||
.get(typ)
|
.get(typ)
|
||||||
.map(|type_config| type_config.icon.clone())
|
.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 this = cx.try_global::<Self>()?;
|
||||||
|
|
||||||
let key = if expanded {
|
let key = if expanded {
|
||||||
|
@ -85,7 +85,7 @@ impl FileIcons {
|
||||||
this.get_type_icon(key)
|
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 this = cx.try_global::<Self>()?;
|
||||||
|
|
||||||
let key = if expanded {
|
let key = if expanded {
|
||||||
|
|
|
@ -94,7 +94,7 @@ enum ClipboardEntry {
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct EntryDetails {
|
pub struct EntryDetails {
|
||||||
filename: String,
|
filename: String,
|
||||||
icon: Option<Arc<str>>,
|
icon: Option<SharedString>,
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
kind: EntryKind,
|
kind: EntryKind,
|
||||||
|
@ -108,7 +108,7 @@ pub struct EntryDetails {
|
||||||
git_status: Option<GitFileStatus>,
|
git_status: Option<GitFileStatus>,
|
||||||
is_private: bool,
|
is_private: bool,
|
||||||
worktree_id: WorktreeId,
|
worktree_id: WorktreeId,
|
||||||
canonical_path: Option<PathBuf>,
|
canonical_path: Option<Box<Path>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Default, Debug, Deserialize)]
|
#[derive(PartialEq, Clone, Default, Debug, Deserialize)]
|
||||||
|
@ -2538,7 +2538,7 @@ impl Render for DraggedProjectEntryView {
|
||||||
.indent_level(self.details.depth)
|
.indent_level(self.details.depth)
|
||||||
.indent_step_size(px(settings.indent_size))
|
.indent_step_size(px(settings.indent_size))
|
||||||
.child(if let Some(icon) = &self.details.icon {
|
.child(if let Some(icon) = &self.details.icon {
|
||||||
div().child(Icon::from_path(icon.to_string()))
|
div().child(Icon::from_path(icon.clone()))
|
||||||
} else {
|
} else {
|
||||||
div()
|
div()
|
||||||
})
|
})
|
||||||
|
|
|
@ -3127,7 +3127,7 @@ pub struct Entry {
|
||||||
pub inode: u64,
|
pub inode: u64,
|
||||||
pub mtime: Option<SystemTime>,
|
pub mtime: Option<SystemTime>,
|
||||||
|
|
||||||
pub canonical_path: Option<PathBuf>,
|
pub canonical_path: Option<Box<Path>>,
|
||||||
pub is_symlink: bool,
|
pub is_symlink: bool,
|
||||||
/// Whether this entry is ignored by Git.
|
/// Whether this entry is ignored by Git.
|
||||||
///
|
///
|
||||||
|
@ -3186,7 +3186,7 @@ impl Entry {
|
||||||
metadata: &fs::Metadata,
|
metadata: &fs::Metadata,
|
||||||
next_entry_id: &AtomicUsize,
|
next_entry_id: &AtomicUsize,
|
||||||
root_char_bag: CharBag,
|
root_char_bag: CharBag,
|
||||||
canonical_path: Option<PathBuf>,
|
canonical_path: Option<Box<Path>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: ProjectEntryId::new(next_entry_id),
|
id: ProjectEntryId::new(next_entry_id),
|
||||||
|
@ -3942,7 +3942,7 @@ impl BackgroundScanner {
|
||||||
child_entry.is_external = true;
|
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() {
|
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();
|
let abs_path: Arc<Path> = root_abs_path.join(&path).into();
|
||||||
match metadata {
|
match metadata {
|
||||||
Ok(Some((metadata, canonical_path))) => {
|
Ok(Some((metadata, canonical_path))) => {
|
||||||
let ignore_stack = state
|
let ignore_stack = state
|
||||||
.snapshot
|
.snapshot
|
||||||
.ignore_stack_for_abs_path(&abs_path, metadata.is_dir);
|
.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(
|
let mut fs_entry = Entry::new(
|
||||||
path.clone(),
|
path.clone(),
|
||||||
metadata,
|
&metadata,
|
||||||
self.next_entry_id.as_ref(),
|
self.next_entry_id.as_ref(),
|
||||||
state.snapshot.root_char_bag,
|
state.snapshot.root_char_bag,
|
||||||
if metadata.is_symlink {
|
if metadata.is_symlink {
|
||||||
Some(canonical_path.to_path_buf())
|
Some(canonical_path.into())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
@ -4096,7 +4096,7 @@ impl BackgroundScanner {
|
||||||
let is_dir = fs_entry.is_dir();
|
let is_dir = fs_entry.is_dir();
|
||||||
fs_entry.is_ignored = ignore_stack.is_abs_path_ignored(&abs_path, 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);
|
fs_entry.is_private = self.is_path_private(path);
|
||||||
|
|
||||||
if !is_dir && !fs_entry.is_ignored && !fs_entry.is_external {
|
if !is_dir && !fs_entry.is_ignored && !fs_entry.is_external {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue