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:
parent
f0f0a52793
commit
8000151aa9
8 changed files with 22 additions and 23 deletions
|
@ -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);
|
||||
|
|
|
@ -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::<Vec<_>>(),
|
||||
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::<Vec<_>>(),
|
||||
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::<Vec<_>>(),
|
||||
cx,
|
||||
)
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
let argument_range = first_arg_start..buffer_position;
|
||||
(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
})
|
||||
|
|
|
@ -4278,9 +4278,9 @@ impl Repository {
|
|||
}));
|
||||
}
|
||||
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, &()) {
|
||||
changed_path_statuses.push(Edit::Remove(PathKey(path.0.clone())));
|
||||
changed_path_statuses.push(Edit::Remove(PathKey(path.0)));
|
||||
}
|
||||
}
|
||||
changed_path_statuses
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue