zed: Reduce clones (#30550)

A collection of small patches that reduce clones. Mostly by using owned
iterators where possible.

Release Notes:

- N/A
This commit is contained in:
tidely 2025-05-12 13:09:23 +03:00 committed by GitHub
parent f0f0a52793
commit 8000151aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 22 additions and 23 deletions

View file

@ -2241,7 +2241,7 @@ impl Thread {
.read(cx) .read(cx)
.enabled_tools(cx) .enabled_tools(cx)
.iter() .iter()
.map(|tool| tool.name().to_string()) .map(|tool| tool.name())
.collect(); .collect();
self.message_feedback.insert(message_id, feedback); self.message_feedback.insert(message_id, feedback);

View file

@ -486,8 +486,8 @@ impl ThreadStore {
ToolSource::Native, ToolSource::Native,
&profile &profile
.tools .tools
.iter() .into_iter()
.filter_map(|(tool, enabled)| enabled.then(|| tool.clone())) .filter_map(|(tool, enabled)| enabled.then(|| tool))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
cx, cx,
); );
@ -511,32 +511,32 @@ impl ThreadStore {
}); });
} }
// Enable all the tools from all context servers, but disable the ones that are explicitly disabled // 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| { self.tools.update(cx, |tools, cx| {
tools.disable( tools.disable(
ToolSource::ContextServer { ToolSource::ContextServer {
id: context_server_id.clone().into(), id: context_server_id.into(),
}, },
&preset &preset
.tools .tools
.iter() .into_iter()
.filter_map(|(tool, enabled)| (!enabled).then(|| tool.clone())) .filter_map(|(tool, enabled)| (!enabled).then(|| tool))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
cx, cx,
) )
}) })
} }
} else { } 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| { self.tools.update(cx, |tools, cx| {
tools.enable( tools.enable(
ToolSource::ContextServer { ToolSource::ContextServer {
id: context_server_id.clone().into(), id: context_server_id.into(),
}, },
&preset &preset
.tools .tools
.iter() .into_iter()
.filter_map(|(tool, enabled)| enabled.then(|| tool.clone())) .filter_map(|(tool, enabled)| enabled.then(|| tool))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
cx, cx,
) )

View file

@ -278,8 +278,8 @@ impl CompletionProvider for SlashCommandCompletionProvider {
buffer.anchor_after(Point::new(position.row, first_arg_start.start as u32)); buffer.anchor_after(Point::new(position.row, first_arg_start.start as u32));
let arguments = call let arguments = call
.arguments .arguments
.iter() .into_iter()
.filter_map(|argument| Some(line.get(argument.clone())?.to_string())) .filter_map(|argument| Some(line.get(argument)?.to_string()))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let argument_range = first_arg_start..buffer_position; let argument_range = first_arg_start..buffer_position;
( (

View file

@ -306,8 +306,7 @@ impl PickerDelegate for BranchListDelegate {
cx.background_executor().clone(), cx.background_executor().clone(),
) )
.await .await
.iter() .into_iter()
.cloned()
.map(|candidate| BranchEntry { .map(|candidate| BranchEntry {
branch: all_branches[candidate.candidate_id].clone(), branch: all_branches[candidate.candidate_id].clone(),
positions: candidate.positions, positions: candidate.positions,

View file

@ -1051,8 +1051,8 @@ impl GitPanel {
repo.checkout_files( repo.checkout_files(
"HEAD", "HEAD",
entries entries
.iter() .into_iter()
.map(|entries| entries.repo_path.clone()) .map(|entries| entries.repo_path)
.collect(), .collect(),
cx, cx,
) )

View file

@ -857,7 +857,7 @@ async fn open_disabled_globs_setting_in_editor(
}); });
if !edits.is_empty() { if !edits.is_empty() {
item.edit(edits.iter().cloned(), cx); item.edit(edits, cx);
} }
let text = item.buffer().read(cx).snapshot(cx).text(); let text = item.buffer().read(cx).snapshot(cx).text();

View file

@ -1238,12 +1238,12 @@ impl Render for LspLogToolbarItemView {
} }
}); });
let available_language_servers: Vec<_> = menu_rows let available_language_servers: Vec<_> = menu_rows
.iter() .into_iter()
.map(|row| { .map(|row| {
( (
row.server_id, row.server_id,
row.server_name.clone(), row.server_name,
row.worktree_root_name.clone(), row.worktree_root_name,
row.selected_entry, row.selected_entry,
) )
}) })

View file

@ -4278,9 +4278,9 @@ impl Repository {
})); }));
} }
let mut cursor = prev_statuses.cursor::<PathProgress>(&()); let mut cursor = prev_statuses.cursor::<PathProgress>(&());
for path in changed_paths.iter() { for path in changed_paths.into_iter() {
if cursor.seek_forward(&PathTarget::Path(&path), Bias::Left, &()) { 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 changed_path_statuses