Make SanitizedPath wrap Path instead of Arc<Path> to avoid allocation (#37106)
Release Notes: - N/A
This commit is contained in:
@@ -62,7 +62,7 @@ use std::{
|
||||
};
|
||||
use sum_tree::{Edit, SumTree, TreeSet};
|
||||
use text::{Bias, BufferId};
|
||||
use util::{ResultExt, debug_panic, post_inc};
|
||||
use util::{ResultExt, debug_panic, paths::SanitizedPath, post_inc};
|
||||
use worktree::{
|
||||
File, PathChange, PathKey, PathProgress, PathSummary, PathTarget, ProjectEntryId,
|
||||
UpdatedGitRepositoriesSet, UpdatedGitRepository, Worktree,
|
||||
@@ -3234,6 +3234,7 @@ impl Repository {
|
||||
let git_store = self.git_store.upgrade()?;
|
||||
let worktree_store = git_store.read(cx).worktree_store.read(cx);
|
||||
let abs_path = self.snapshot.work_directory_abs_path.join(&path.0);
|
||||
let abs_path = SanitizedPath::new(&abs_path);
|
||||
let (worktree, relative_path) = worktree_store.find_worktree(abs_path, cx)?;
|
||||
Some(ProjectPath {
|
||||
worktree_id: worktree.read(cx).id(),
|
||||
|
||||
@@ -3186,7 +3186,7 @@ impl LocalLspStore {
|
||||
} else {
|
||||
let (path, pattern) = match &watcher.glob_pattern {
|
||||
lsp::GlobPattern::String(s) => {
|
||||
let watcher_path = SanitizedPath::from(s);
|
||||
let watcher_path = SanitizedPath::new(s);
|
||||
let path = glob_literal_prefix(watcher_path.as_path());
|
||||
let pattern = watcher_path
|
||||
.as_path()
|
||||
@@ -3278,7 +3278,7 @@ impl LocalLspStore {
|
||||
let worktree_root_path = tree.abs_path();
|
||||
match &watcher.glob_pattern {
|
||||
lsp::GlobPattern::String(s) => {
|
||||
let watcher_path = SanitizedPath::from(s);
|
||||
let watcher_path = SanitizedPath::new(s);
|
||||
let relative = watcher_path
|
||||
.as_path()
|
||||
.strip_prefix(&worktree_root_path)
|
||||
|
||||
@@ -2061,13 +2061,12 @@ impl Project {
|
||||
exclude_sub_dirs: bool,
|
||||
cx: &App,
|
||||
) -> Option<bool> {
|
||||
let sanitized_path = SanitizedPath::from(path);
|
||||
let path = sanitized_path.as_path();
|
||||
let path = SanitizedPath::new(path).as_path();
|
||||
self.worktrees(cx)
|
||||
.filter_map(|worktree| {
|
||||
let worktree = worktree.read(cx);
|
||||
let abs_path = worktree.as_local()?.abs_path();
|
||||
let contains = path == abs_path
|
||||
let contains = path == abs_path.as_ref()
|
||||
|| (path.starts_with(abs_path) && (!exclude_sub_dirs || !metadata.is_dir));
|
||||
contains.then(|| worktree.is_visible())
|
||||
})
|
||||
|
||||
@@ -61,7 +61,7 @@ pub struct WorktreeStore {
|
||||
worktrees_reordered: bool,
|
||||
#[allow(clippy::type_complexity)]
|
||||
loading_worktrees:
|
||||
HashMap<SanitizedPath, Shared<Task<Result<Entity<Worktree>, Arc<anyhow::Error>>>>>,
|
||||
HashMap<Arc<SanitizedPath>, Shared<Task<Result<Entity<Worktree>, Arc<anyhow::Error>>>>>,
|
||||
state: WorktreeStoreState,
|
||||
}
|
||||
|
||||
@@ -153,10 +153,10 @@ impl WorktreeStore {
|
||||
|
||||
pub fn find_worktree(
|
||||
&self,
|
||||
abs_path: impl Into<SanitizedPath>,
|
||||
abs_path: impl AsRef<Path>,
|
||||
cx: &App,
|
||||
) -> Option<(Entity<Worktree>, PathBuf)> {
|
||||
let abs_path: SanitizedPath = abs_path.into();
|
||||
let abs_path = SanitizedPath::new(&abs_path);
|
||||
for tree in self.worktrees() {
|
||||
if let Ok(relative_path) = abs_path.as_path().strip_prefix(tree.read(cx).abs_path()) {
|
||||
return Some((tree.clone(), relative_path.into()));
|
||||
@@ -212,11 +212,11 @@ impl WorktreeStore {
|
||||
|
||||
pub fn create_worktree(
|
||||
&mut self,
|
||||
abs_path: impl Into<SanitizedPath>,
|
||||
abs_path: impl AsRef<Path>,
|
||||
visible: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Worktree>>> {
|
||||
let abs_path: SanitizedPath = abs_path.into();
|
||||
let abs_path: Arc<SanitizedPath> = SanitizedPath::new_arc(&abs_path);
|
||||
if !self.loading_worktrees.contains_key(&abs_path) {
|
||||
let task = match &self.state {
|
||||
WorktreeStoreState::Remote {
|
||||
@@ -227,8 +227,7 @@ impl WorktreeStore {
|
||||
if upstream_client.is_via_collab() {
|
||||
Task::ready(Err(Arc::new(anyhow!("cannot create worktrees via collab"))))
|
||||
} else {
|
||||
let abs_path =
|
||||
RemotePathBuf::new(abs_path.as_path().to_path_buf(), *path_style);
|
||||
let abs_path = RemotePathBuf::new(abs_path.to_path_buf(), *path_style);
|
||||
self.create_ssh_worktree(upstream_client.clone(), abs_path, visible, cx)
|
||||
}
|
||||
}
|
||||
@@ -321,15 +320,21 @@ impl WorktreeStore {
|
||||
fn create_local_worktree(
|
||||
&mut self,
|
||||
fs: Arc<dyn Fs>,
|
||||
abs_path: impl Into<SanitizedPath>,
|
||||
abs_path: Arc<SanitizedPath>,
|
||||
visible: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Worktree>, Arc<anyhow::Error>>> {
|
||||
let next_entry_id = self.next_entry_id.clone();
|
||||
let path: SanitizedPath = abs_path.into();
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
let worktree = Worktree::local(path.clone(), visible, fs, next_entry_id, cx).await;
|
||||
let worktree = Worktree::local(
|
||||
SanitizedPath::cast_arc(abs_path.clone()),
|
||||
visible,
|
||||
fs,
|
||||
next_entry_id,
|
||||
cx,
|
||||
)
|
||||
.await;
|
||||
|
||||
let worktree = worktree?;
|
||||
|
||||
@@ -337,7 +342,7 @@ impl WorktreeStore {
|
||||
|
||||
if visible {
|
||||
cx.update(|cx| {
|
||||
cx.add_recent_document(path.as_path());
|
||||
cx.add_recent_document(abs_path.as_path());
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user