Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Reduce allocations (#30693)
tidelybc99a86bb720
diff --git a/crates/agent/src/context_picker.rs b/crates/agent/src/context_picker.rsindex cd7288c3112..3f29e12f3bd 100644--- a/crates/agent/src/context_picker.rs+++ b/crates/agent/src/context_picker.rs@@ -942,8 +942,8 @@ impl MentionLink {format!("[@{}]({}:{})", title, Self::THREAD, id)}ThreadContextEntry::Context { path, title } => {- let filename = path.file_name().unwrap_or_default();- let escaped_filename = urlencoding::encode(&filename.to_string_lossy()).to_string();+ let filename = path.file_name().unwrap_or_default().to_string_lossy();+ let escaped_filename = urlencoding::encode(&filename);format!("[@{}]({}:{}{})",title,diff --git a/crates/agent/src/terminal_inline_assistant.rs b/crates/agent/src/terminal_inline_assistant.rsindex 64e23fba14c..992f32af985 100644--- a/crates/agent/src/terminal_inline_assistant.rs+++ b/crates/agent/src/terminal_inline_assistant.rs@@ -191,7 +191,7 @@ impl TerminalInlineAssistant {};self.prompt_history.retain(|prompt| *prompt != user_prompt);- self.prompt_history.push_back(user_prompt.clone());+ self.prompt_history.push_back(user_prompt);if self.prompt_history.len() > PROMPT_HISTORY_MAX_LEN {self.prompt_history.pop_front();}diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rsindex 5790be66440..98c67804ab2 100644--- a/crates/agent/src/thread.rs+++ b/crates/agent/src/thread.rs@@ -2583,7 +2583,7 @@ impl Thread {.read(cx).current_user().map(|user| user.github_login.clone());- let client = self.project.read(cx).client().clone();+ let client = self.project.read(cx).client();let serialize_task = self.serialize(cx);cx.background_executor()diff --git a/crates/agent/src/thread_history.rs b/crates/agent/src/thread_history.rsindex 353291f4e37..43427229375 100644--- a/crates/agent/src/thread_history.rs+++ b/crates/agent/src/thread_history.rs@@ -260,10 +260,7 @@ impl ThreadHistory {}});- self.search_state = SearchState::Searching {- query: query.clone(),- _task: task,- };+ self.search_state = SearchState::Searching { query, _task: task };cx.notify();}diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rsindex 42ca88e2f20..53d446dc251 100644--- a/crates/assistant_context_editor/src/context_editor.rs+++ b/crates/assistant_context_editor/src/context_editor.rs@@ -3044,7 +3044,7 @@ fn invoked_slash_command_fold_placeholder(.gap_2().bg(cx.theme().colors().surface_background).rounded_sm()- .child(Label::new(format!("/{}", command.name.clone())))+ .child(Label::new(format!("/{}", command.name))).map(|parent| match &command.status {InvokedSlashCommandStatus::Running(_) => {parent.child(Icon::new(IconName::ArrowCircle).with_animation(diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rsindex fa7690a6a36..500aa528c29 100644--- a/crates/client/src/telemetry.rs+++ b/crates/client/src/telemetry.rs@@ -137,18 +137,14 @@ pub fn os_version() -> String {log::error!("Failed to load /etc/os-release, /usr/lib/os-release");"".to_string()};- let mut name = "unknown".to_string();- let mut version = "unknown".to_string();+ let mut name = "unknown";+ let mut version = "unknown";for line in content.lines() {- if line.starts_with("ID=") {- name = line.trim_start_matches("ID=").trim_matches('"').to_string();- }- if line.starts_with("VERSION_ID=") {- version = line- .trim_start_matches("VERSION_ID=")- .trim_matches('"')- .to_string();+ match line.split_once('=') {+ Some(("ID", val)) => name = val.trim_matches('"'),+ Some(("VERSION_ID", val)) => version = val.trim_matches('"'),+ _ => {}}}@@ -222,7 +218,7 @@ impl Telemetry {cx.background_spawn({let state = state.clone();let os_version = os_version();- state.lock().os_version = Some(os_version.clone());+ state.lock().os_version = Some(os_version);async move {if let Some(tempfile) = File::create(Self::log_file_path()).log_err() {state.lock().log_file = Some(tempfile);diff --git a/crates/collab_ui/src/chat_panel.rs b/crates/collab_ui/src/chat_panel.rsindex 0eee89d1fec..55b7ade771e 100644--- a/crates/collab_ui/src/chat_panel.rs+++ b/crates/collab_ui/src/chat_panel.rs@@ -1059,7 +1059,7 @@ impl Render for ChatPanel {.child(Label::new(format!("@{}",- user_being_replied_to.github_login.clone()+ user_being_replied_to.github_login)).size(LabelSize::Small).weight(FontWeight::BOLD),diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rsindex a98adb0fb81..72eae3726c4 100644--- a/crates/debugger_ui/src/session/running/console.rs+++ b/crates/debugger_ui/src/session/running/console.rs@@ -365,7 +365,7 @@ impl ConsoleQueryBarCompletionProvider {new_text: string_match.string.clone(),label: CodeLabel {filter_range: 0..string_match.string.len(),- text: format!("{} {}", string_match.string.clone(), variable_value),+ text: format!("{} {}", string_match.string, variable_value),runs: Vec::new(),},icon_path: None,diff --git a/crates/extensions_ui/src/extensions_ui.rs b/crates/extensions_ui/src/extensions_ui.rsindex 15c73effeeb..03836873047 100644--- a/crates/extensions_ui/src/extensions_ui.rs+++ b/crates/extensions_ui/src/extensions_ui.rs@@ -955,7 +955,7 @@ impl ExtensionsPage {.disabled(true),configure: is_configurable.then(|| {Button::new(- SharedString::from(format!("configure-{}", extension.id.clone())),+ SharedString::from(format!("configure-{}", extension.id)),"Configure",).disabled(true)@@ -980,7 +980,7 @@ impl ExtensionsPage {}),configure: is_configurable.then(|| {Button::new(- SharedString::from(format!("configure-{}", extension.id.clone())),+ SharedString::from(format!("configure-{}", extension.id)),"Configure",).on_click({@@ -1049,7 +1049,7 @@ impl ExtensionsPage {.disabled(true),configure: is_configurable.then(|| {Button::new(- SharedString::from(format!("configure-{}", extension.id.clone())),+ SharedString::from(format!("configure-{}", extension.id)),"Configure",).disabled(true)diff --git a/crates/file_finder/src/new_path_prompt.rs b/crates/file_finder/src/new_path_prompt.rsindex e4d5ff0618b..69b473e146a 100644--- a/crates/file_finder/src/new_path_prompt.rs+++ b/crates/file_finder/src/new_path_prompt.rs@@ -354,8 +354,9 @@ impl PickerDelegate for NewPathDelegate {let m = self.matches.get(self.selected_index)?;if m.is_dir(self.project.read(cx), cx) {let path = m.relative_path();- self.last_selected_dir = Some(path.clone());- Some(format!("{}/", path))+ let result = format!("{}/", path);+ self.last_selected_dir = Some(path);+ Some(result)} else {None}diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rsindex 03acd514a1d..1d016368237 100644--- a/crates/git_ui/src/git_panel.rs+++ b/crates/git_ui/src/git_panel.rs@@ -2583,19 +2583,18 @@ impl GitPanel {} else {workspace.update(cx, |workspace, cx| {let workspace_weak = cx.weak_entity();- let toast =- StatusToast::new(format!("git {} failed", action.clone()), cx, |this, _cx| {- this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))- .action("View Log", move |window, cx| {- let message = message.clone();- let action = action.clone();- workspace_weak- .update(cx, move |workspace, cx| {- Self::open_output(action, workspace, &message, window, cx)- })- .ok();- })- });+ let toast = StatusToast::new(format!("git {} failed", action), cx, |this, _cx| {+ this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))+ .action("View Log", move |window, cx| {+ let message = message.clone();+ let action = action.clone();+ workspace_weak+ .update(cx, move |workspace, cx| {+ Self::open_output(action, workspace, &message, window, cx)+ })+ .ok();+ })+ });workspace.toggle_status_toast(toast, cx)});}diff --git a/crates/proto/src/error.rs b/crates/proto/src/error.rsindex 680056fc1c2..8d9c1015d9c 100644--- a/crates/proto/src/error.rs+++ b/crates/proto/src/error.rs@@ -134,7 +134,7 @@ impl From<ErrorCode> for anyhow::Error {RpcError {request: None,code: value,- msg: format!("{:?}", value).to_string(),+ msg: format!("{:?}", value),tags: Default::default(),}.into()@@ -241,7 +241,7 @@ impl From<ErrorCode> for RpcError {RpcError {request: None,code,- msg: format!("{:?}", code).to_string(),+ msg: format!("{:?}", code),tags: Default::default(),}}diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rsindex 0d49cf39557..f50e945df35 100644--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@ -1946,9 +1946,9 @@ impl Render for ProjectSearchBar {if match_quantity > 0 {debug_assert!(match_quantity >= index);if limit_reached {- Some(format!("{index}/{match_quantity}+").to_string())+ Some(format!("{index}/{match_quantity}+"))} else {- Some(format!("{index}/{match_quantity}").to_string())+ Some(format!("{index}/{match_quantity}"))}} else {Nonediff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rsindex 56f269b0086..507fd4df100 100644--- a/crates/terminal/src/terminal.rs+++ b/crates/terminal/src/terminal.rs@@ -269,13 +269,12 @@ impl TerminalError {Err(s) => s,}})- .unwrap_or_else(|| {- let default_dir =- dirs::home_dir().map(|buf| buf.into_os_string().to_string_lossy().to_string());- match default_dir {- Some(dir) => format!("<none specified, using home directory> {}", dir),- None => "<none specified, could not find home directory>".to_string(),- }+ .unwrap_or_else(|| match dirs::home_dir() {+ Some(dir) => format!(+ "<none specified, using home directory> {}",+ dir.into_os_string().to_string_lossy()+ ),+ None => "<none specified, could not find home directory>".to_string(),})}diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rsindex bb77e6ac43b..c629981541b 100644--- a/crates/title_bar/src/title_bar.rs+++ b/crates/title_bar/src/title_bar.rs@@ -475,7 +475,7 @@ impl TitleBar {.label_size(LabelSize::Small).tooltip(Tooltip::text(format!("{} is sharing this project. Click to follow.",- host_user.github_login.clone()+ host_user.github_login))).on_click({let host_peer_id = host.peer_id;diff --git a/crates/ui/src/components/modal.rs b/crates/ui/src/components/modal.rsindex 7b2c8beb62f..2e926b75938 100644--- a/crates/ui/src/components/modal.rs+++ b/crates/ui/src/components/modal.rs@@ -20,7 +20,7 @@ impl Modal {pub fn new(id: impl Into<SharedString>, scroll_handle: Option<ScrollHandle>) -> Self {let id = id.into();- let container_id = ElementId::Name(format!("{}_container", id.clone()).into());+ let container_id = ElementId::Name(format!("{}_container", id).into());Self {id: ElementId::Name(id),header: ModalHeader::new(),diff --git a/crates/zed/src/zed/quick_action_bar/repl_menu.rs b/crates/zed/src/zed/quick_action_bar/repl_menu.rsindex a7e00adf0c7..12e5cf1b769 100644--- a/crates/zed/src/zed/quick_action_bar/repl_menu.rs+++ b/crates/zed/src/zed/quick_action_bar/repl_menu.rs@@ -77,7 +77,7 @@ impl QuickActionBar {let menu_state = session_state(session.clone(), cx);- let id = "repl-menu".to_string();+ let id = "repl-menu";let element_id = |suffix| ElementId::Name(format!("{}-{}", id, suffix).into());@@ -99,8 +99,7 @@ impl QuickActionBar {.child(Label::new(format!("kernel: {} ({})",- menu_state.kernel_name.clone(),- menu_state.kernel_language.clone()+ menu_state.kernel_name, menu_state.kernel_language)).size(LabelSize::Small).color(Color::Muted),@@ -121,7 +120,7 @@ impl QuickActionBar {menu.custom_row(move |_window, _cx| {h_flex().child(- Label::new(format!("{}...", status.clone().to_string()))+ Label::new(format!("{}...", status.to_string())).size(LabelSize::Small).color(Color::Muted),)