From 8000151aa9486d01c22c17c6afbc580606145753 Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Mon, 12 May 2025 13:09:23 +0300 Subject: [PATCH] zed: Reduce clones (#30550) A collection of small patches that reduce clones. Mostly by using owned iterators where possible. Release Notes: - N/A --- crates/agent/src/thread.rs | 2 +- crates/agent/src/thread_store.rs | 20 +++++++++---------- .../src/slash_command.rs | 4 ++-- crates/git_ui/src/branch_picker.rs | 3 +-- crates/git_ui/src/git_panel.rs | 4 ++-- .../src/inline_completion_button.rs | 2 +- crates/language_tools/src/lsp_log.rs | 6 +++--- crates/project/src/git_store.rs | 4 ++-- 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index a65eda5b40c123b75197ec3fd99a57753e7c9ed7..93b9a73d947fb7e565cdad97d653e8c306793ddf 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -2241,7 +2241,7 @@ impl Thread { .read(cx) .enabled_tools(cx) .iter() - .map(|tool| tool.name().to_string()) + .map(|tool| tool.name()) .collect(); self.message_feedback.insert(message_id, feedback); diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rs index 99ecd3d4420fdbc374ed7875dad43880dd967136..508ddfa05183cfb934c342bb5418648420657f1e 100644 --- a/crates/agent/src/thread_store.rs +++ b/crates/agent/src/thread_store.rs @@ -486,8 +486,8 @@ impl ThreadStore { ToolSource::Native, &profile .tools - .iter() - .filter_map(|(tool, enabled)| enabled.then(|| tool.clone())) + .into_iter() + .filter_map(|(tool, enabled)| enabled.then(|| tool)) .collect::>(), cx, ); @@ -511,32 +511,32 @@ impl ThreadStore { }); } // Enable all the tools from all context servers, but disable the ones that are explicitly disabled - for (context_server_id, preset) in &profile.context_servers { + for (context_server_id, preset) in profile.context_servers { self.tools.update(cx, |tools, cx| { tools.disable( ToolSource::ContextServer { - id: context_server_id.clone().into(), + id: context_server_id.into(), }, &preset .tools - .iter() - .filter_map(|(tool, enabled)| (!enabled).then(|| tool.clone())) + .into_iter() + .filter_map(|(tool, enabled)| (!enabled).then(|| tool)) .collect::>(), cx, ) }) } } else { - for (context_server_id, preset) in &profile.context_servers { + for (context_server_id, preset) in profile.context_servers { self.tools.update(cx, |tools, cx| { tools.enable( ToolSource::ContextServer { - id: context_server_id.clone().into(), + id: context_server_id.into(), }, &preset .tools - .iter() - .filter_map(|(tool, enabled)| enabled.then(|| tool.clone())) + .into_iter() + .filter_map(|(tool, enabled)| enabled.then(|| tool)) .collect::>(), cx, ) diff --git a/crates/assistant_context_editor/src/slash_command.rs b/crates/assistant_context_editor/src/slash_command.rs index 1cbcb4a63794526b3910b4268979fbeabf2de39c..b0f16e53a78651f2ca03e3e6e5adc50bbbecc17b 100644 --- a/crates/assistant_context_editor/src/slash_command.rs +++ b/crates/assistant_context_editor/src/slash_command.rs @@ -278,8 +278,8 @@ impl CompletionProvider for SlashCommandCompletionProvider { buffer.anchor_after(Point::new(position.row, first_arg_start.start as u32)); let arguments = call .arguments - .iter() - .filter_map(|argument| Some(line.get(argument.clone())?.to_string())) + .into_iter() + .filter_map(|argument| Some(line.get(argument)?.to_string())) .collect::>(); let argument_range = first_arg_start..buffer_position; ( diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rs index 2530bacf8d76780f946f40e7593c9c179c0dc153..04c5575d1fd34b9c16236a5d566deed0b7bdc3cc 100644 --- a/crates/git_ui/src/branch_picker.rs +++ b/crates/git_ui/src/branch_picker.rs @@ -306,8 +306,7 @@ impl PickerDelegate for BranchListDelegate { cx.background_executor().clone(), ) .await - .iter() - .cloned() + .into_iter() .map(|candidate| BranchEntry { branch: all_branches[candidate.candidate_id].clone(), positions: candidate.positions, diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 738e0f62a3e240c9f7c71300d6fa04add4cad917..03acd514a1d910aa08441074fa7d05315d195a60 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -1051,8 +1051,8 @@ impl GitPanel { repo.checkout_files( "HEAD", entries - .iter() - .map(|entries| entries.repo_path.clone()) + .into_iter() + .map(|entries| entries.repo_path) .collect(), cx, ) diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index 296b169950dbd15dbcce0b73cbbf17877a2798c1..fd25823307bdf651ed73d2968d210b2fe522a057 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/crates/inline_completion_button/src/inline_completion_button.rs @@ -857,7 +857,7 @@ async fn open_disabled_globs_setting_in_editor( }); if !edits.is_empty() { - item.edit(edits.iter().cloned(), cx); + item.edit(edits, cx); } let text = item.buffer().read(cx).snapshot(cx).text(); diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index 8b29ab6298ef58fa6dcc7c8041b3fcac209a52fa..9c124599b2fc3c0377cede262c6bbf563ef1189a 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -1238,12 +1238,12 @@ impl Render for LspLogToolbarItemView { } }); let available_language_servers: Vec<_> = menu_rows - .iter() + .into_iter() .map(|row| { ( row.server_id, - row.server_name.clone(), - row.worktree_root_name.clone(), + row.server_name, + row.worktree_root_name, row.selected_entry, ) }) diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index d00f0a41fdf7fd63e4ab3e8c70c7b367d2985678..5d6fcdb503345f9604e5258a4323b5d3a6fbd4ef 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -4278,9 +4278,9 @@ impl Repository { })); } let mut cursor = prev_statuses.cursor::(&()); - for path in changed_paths.iter() { + for path in changed_paths.into_iter() { if cursor.seek_forward(&PathTarget::Path(&path), Bias::Left, &()) { - changed_path_statuses.push(Edit::Remove(PathKey(path.0.clone()))); + changed_path_statuses.push(Edit::Remove(PathKey(path.0))); } } changed_path_statuses