From fbc922ad466d4a85e2fe7d1ce00e010c3457c26c Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Fri, 23 May 2025 14:25:17 +0300 Subject: [PATCH] Reduce allocations (#31223) Release Notes: - N/A --- crates/gpui/src/platform/windows/destination_list.rs | 4 ++-- crates/gpui/src/platform/windows/display.rs | 2 +- crates/project/src/debugger/locators/cargo.rs | 8 ++------ crates/project/src/search.rs | 6 ++---- crates/project/src/task_inventory.rs | 4 ++-- crates/project/src/terminals.rs | 10 +++++----- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/gpui/src/platform/windows/destination_list.rs b/crates/gpui/src/platform/windows/destination_list.rs index 37ffd57d12..fdfa52aaec 100644 --- a/crates/gpui/src/platform/windows/destination_list.rs +++ b/crates/gpui/src/platform/windows/destination_list.rs @@ -158,8 +158,8 @@ fn add_recent_folders( .iter() .map(|p| { p.file_name() - .map(|name| name.to_string_lossy().to_string()) - .unwrap_or_else(|| p.to_string_lossy().to_string()) + .map(|name| name.to_string_lossy()) + .unwrap_or_else(|| p.to_string_lossy()) }) .join(", "); diff --git a/crates/gpui/src/platform/windows/display.rs b/crates/gpui/src/platform/windows/display.rs index 2e7deb7f62..79716c951d 100644 --- a/crates/gpui/src/platform/windows/display.rs +++ b/crates/gpui/src/platform/windows/display.rs @@ -241,7 +241,7 @@ fn get_monitor_info(hmonitor: HMONITOR) -> anyhow::Result { fn generate_uuid(device_name: &[u16]) -> Uuid { let name = device_name .iter() - .flat_map(|&a| a.to_be_bytes().to_vec()) + .flat_map(|&a| a.to_be_bytes()) .collect_vec(); Uuid::new_v5(&Uuid::NAMESPACE_DNS, &name) } diff --git a/crates/project/src/debugger/locators/cargo.rs b/crates/project/src/debugger/locators/cargo.rs index bac81a6b1a..17df2c8c0e 100644 --- a/crates/project/src/debugger/locators/cargo.rs +++ b/crates/project/src/debugger/locators/cargo.rs @@ -164,13 +164,9 @@ impl DapLocator for CargoLocator { Ok(DebugRequest::Launch(task::LaunchRequest { program: executable, - cwd: build_config.cwd.clone(), + cwd: build_config.cwd, args, - env: build_config - .env - .iter() - .map(|(k, v)| (k.clone(), v.clone())) - .collect(), + env: build_config.env.into_iter().collect(), })) } } diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs index fe7d83b6fb..d3585115f5 100644 --- a/crates/project/src/search.rs +++ b/crates/project/src/search.rs @@ -521,10 +521,8 @@ pub fn deserialize_path_matches(glob_set: &str) -> anyhow::Result { let globs = glob_set .split(',') .map(str::trim) - .filter(|&glob_str| (!glob_str.is_empty())) - .map(|glob_str| glob_str.to_owned()) - .collect::>(); - Ok(PathMatcher::new(&globs)?) + .filter(|&glob_str| !glob_str.is_empty()); + Ok(PathMatcher::new(globs)?) } #[cfg(test)] diff --git a/crates/project/src/task_inventory.rs b/crates/project/src/task_inventory.rs index f53bc8e633..8ec561f48e 100644 --- a/crates/project/src/task_inventory.rs +++ b/crates/project/src/task_inventory.rs @@ -306,9 +306,9 @@ impl Inventory { .unwrap_or((None, None, None)); self.list_tasks(file, language, worktree_id.or(buffer_worktree_id), cx) - .iter() + .into_iter() .find(|(_, template)| template.label == label) - .map(|val| val.1.clone()) + .map(|val| val.1) } /// Pulls its task sources relevant to the worktree and the language given, diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index f666978b61..7a96aba4e5 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -108,14 +108,14 @@ impl Project { }); } } - let settings = TerminalSettings::get(settings_location, cx).clone(); + let venv = TerminalSettings::get(settings_location, cx) + .detect_venv + .clone(); cx.spawn(async move |project, cx| { - let python_venv_directory = if let Some(path) = path.clone() { + let python_venv_directory = if let Some(path) = path { project - .update(cx, |this, cx| { - this.python_venv_directory(path, settings.detect_venv.clone(), cx) - })? + .update(cx, |this, cx| this.python_venv_directory(path, venv, cx))? .await } else { None