From c69d0d50cd251525045a9f5f328ffd4c3e9c4e0f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 14 Jul 2023 13:03:04 -0700 Subject: [PATCH 1/2] Avoid deserializing all themes to compute settings JSON schema --- crates/theme/src/theme_registry.rs | 22 +++++++++++++++++----- crates/theme/src/theme_settings.rs | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/theme/src/theme_registry.rs b/crates/theme/src/theme_registry.rs index 8565bc3b567ab04f0d68ae6637da5c498d595084..617667bc9feb05b8f5ed4e02da7cb14d3781546e 100644 --- a/crates/theme/src/theme_registry.rs +++ b/crates/theme/src/theme_registry.rs @@ -5,6 +5,7 @@ use parking_lot::Mutex; use serde::Deserialize; use serde_json::Value; use std::{ + borrow::Cow, collections::HashMap, sync::{ atomic::{AtomicUsize, Ordering::SeqCst}, @@ -43,7 +44,7 @@ impl ThemeRegistry { this } - pub fn list(&self, staff: bool) -> impl Iterator + '_ { + pub fn list_names(&self, staff: bool) -> impl Iterator> + '_ { let mut dirs = self.assets.list("themes/"); if !staff { @@ -53,10 +54,21 @@ impl ThemeRegistry { .collect() } - dirs.into_iter().filter_map(|path| { - let filename = path.strip_prefix("themes/")?; - let theme_name = filename.strip_suffix(".json")?; - self.get(theme_name).ok().map(|theme| theme.meta.clone()) + fn get_name(path: &str) -> Option<&str> { + path.strip_prefix("themes/")?.strip_suffix(".json") + } + + dirs.into_iter().filter_map(|path| match path { + Cow::Borrowed(path) => Some(Cow::Borrowed(get_name(path)?)), + Cow::Owned(path) => Some(Cow::Owned(get_name(&path)?.to_string())), + }) + } + + pub fn list(&self, staff: bool) -> impl Iterator + '_ { + self.list_names(staff).filter_map(|theme_name| { + self.get(theme_name.as_ref()) + .ok() + .map(|theme| theme.meta.clone()) }) } diff --git a/crates/theme/src/theme_settings.rs b/crates/theme/src/theme_settings.rs index 359ed8e511853f1db0b841d7bfbc1124dd173587..b576391e14b841a42c826196ce41471e8ab332c4 100644 --- a/crates/theme/src/theme_settings.rs +++ b/crates/theme/src/theme_settings.rs @@ -178,8 +178,8 @@ impl settings::Setting for ThemeSettings { let mut root_schema = generator.root_schema_for::(); let theme_names = cx .global::>() - .list(params.staff_mode) - .map(|theme| Value::String(theme.name.clone())) + .list_names(params.staff_mode) + .map(|theme_name| Value::String(theme_name.to_string())) .collect(); let theme_name_schema = SchemaObject { From b9e00747932d66ddf98e73801d71930520a934ae Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 14 Jul 2023 13:52:18 -0700 Subject: [PATCH 2/2] Perform only one git statuses call when reloading a git repo after it changes --- crates/fs/src/repository.rs | 1 + crates/project/src/worktree.rs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fs/src/repository.rs b/crates/fs/src/repository.rs index ed9aa85a89bf991bf1d03d5f8952dd8fb70a9780..3826dae2aa73eeb3f5c263d0291e932939a19fff 100644 --- a/crates/fs/src/repository.rs +++ b/crates/fs/src/repository.rs @@ -33,6 +33,7 @@ pub trait GitRepository: Send { fn statuses(&self) -> Option>; fn status(&self, path: &RepoPath) -> Result>; + fn branches(&self) -> Result> { Ok(vec![]) } diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index b113af34ad40c9f06d5fa2989aee94219c2091b6..a1730fd365f9dd13002a94011acf0c187b06b6d5 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -2023,6 +2023,9 @@ impl LocalSnapshot { ) -> Vec> { let mut changes = vec![]; let mut edits = vec![]; + + let statuses = repo_ptr.statuses(); + for mut entry in self .descendent_entries(false, false, &work_directory.0) .cloned() @@ -2030,10 +2033,8 @@ impl LocalSnapshot { let Ok(repo_path) = entry.path.strip_prefix(&work_directory.0) else { continue; }; - let git_file_status = repo_ptr - .status(&RepoPath(repo_path.into())) - .log_err() - .flatten(); + let repo_path = RepoPath(repo_path.to_path_buf()); + let git_file_status = statuses.as_ref().and_then(|s| s.get(&repo_path).copied()); if entry.git_status != git_file_status { entry.git_status = git_file_status; changes.push(entry.path.clone());