Reduce allocations (#30693)
Removes a unnecessary string conversion and some clones Release Notes: - N/A
This commit is contained in:
parent
fcfe4e2c14
commit
bc99a86bb7
17 changed files with 48 additions and 57 deletions
|
@ -942,8 +942,8 @@ impl MentionLink {
|
||||||
format!("[@{}]({}:{})", title, Self::THREAD, id)
|
format!("[@{}]({}:{})", title, Self::THREAD, id)
|
||||||
}
|
}
|
||||||
ThreadContextEntry::Context { path, title } => {
|
ThreadContextEntry::Context { path, title } => {
|
||||||
let filename = path.file_name().unwrap_or_default();
|
let filename = path.file_name().unwrap_or_default().to_string_lossy();
|
||||||
let escaped_filename = urlencoding::encode(&filename.to_string_lossy()).to_string();
|
let escaped_filename = urlencoding::encode(&filename);
|
||||||
format!(
|
format!(
|
||||||
"[@{}]({}:{}{})",
|
"[@{}]({}:{}{})",
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl TerminalInlineAssistant {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.prompt_history.retain(|prompt| *prompt != user_prompt);
|
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 {
|
if self.prompt_history.len() > PROMPT_HISTORY_MAX_LEN {
|
||||||
self.prompt_history.pop_front();
|
self.prompt_history.pop_front();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2583,7 +2583,7 @@ impl Thread {
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.current_user()
|
.current_user()
|
||||||
.map(|user| user.github_login.clone());
|
.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);
|
let serialize_task = self.serialize(cx);
|
||||||
|
|
||||||
cx.background_executor()
|
cx.background_executor()
|
||||||
|
|
|
@ -260,10 +260,7 @@ impl ThreadHistory {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.search_state = SearchState::Searching {
|
self.search_state = SearchState::Searching { query, _task: task };
|
||||||
query: query.clone(),
|
|
||||||
_task: task,
|
|
||||||
};
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3044,7 +3044,7 @@ fn invoked_slash_command_fold_placeholder(
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.bg(cx.theme().colors().surface_background)
|
.bg(cx.theme().colors().surface_background)
|
||||||
.rounded_sm()
|
.rounded_sm()
|
||||||
.child(Label::new(format!("/{}", command.name.clone())))
|
.child(Label::new(format!("/{}", command.name)))
|
||||||
.map(|parent| match &command.status {
|
.map(|parent| match &command.status {
|
||||||
InvokedSlashCommandStatus::Running(_) => {
|
InvokedSlashCommandStatus::Running(_) => {
|
||||||
parent.child(Icon::new(IconName::ArrowCircle).with_animation(
|
parent.child(Icon::new(IconName::ArrowCircle).with_animation(
|
||||||
|
|
|
@ -137,18 +137,14 @@ pub fn os_version() -> String {
|
||||||
log::error!("Failed to load /etc/os-release, /usr/lib/os-release");
|
log::error!("Failed to load /etc/os-release, /usr/lib/os-release");
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
let mut name = "unknown".to_string();
|
let mut name = "unknown";
|
||||||
let mut version = "unknown".to_string();
|
let mut version = "unknown";
|
||||||
|
|
||||||
for line in content.lines() {
|
for line in content.lines() {
|
||||||
if line.starts_with("ID=") {
|
match line.split_once('=') {
|
||||||
name = line.trim_start_matches("ID=").trim_matches('"').to_string();
|
Some(("ID", val)) => name = val.trim_matches('"'),
|
||||||
}
|
Some(("VERSION_ID", val)) => version = val.trim_matches('"'),
|
||||||
if line.starts_with("VERSION_ID=") {
|
_ => {}
|
||||||
version = line
|
|
||||||
.trim_start_matches("VERSION_ID=")
|
|
||||||
.trim_matches('"')
|
|
||||||
.to_string();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +218,7 @@ impl Telemetry {
|
||||||
cx.background_spawn({
|
cx.background_spawn({
|
||||||
let state = state.clone();
|
let state = state.clone();
|
||||||
let os_version = os_version();
|
let os_version = os_version();
|
||||||
state.lock().os_version = Some(os_version.clone());
|
state.lock().os_version = Some(os_version);
|
||||||
async move {
|
async move {
|
||||||
if let Some(tempfile) = File::create(Self::log_file_path()).log_err() {
|
if let Some(tempfile) = File::create(Self::log_file_path()).log_err() {
|
||||||
state.lock().log_file = Some(tempfile);
|
state.lock().log_file = Some(tempfile);
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ impl Render for ChatPanel {
|
||||||
.child(
|
.child(
|
||||||
Label::new(format!(
|
Label::new(format!(
|
||||||
"@{}",
|
"@{}",
|
||||||
user_being_replied_to.github_login.clone()
|
user_being_replied_to.github_login
|
||||||
))
|
))
|
||||||
.size(LabelSize::Small)
|
.size(LabelSize::Small)
|
||||||
.weight(FontWeight::BOLD),
|
.weight(FontWeight::BOLD),
|
||||||
|
|
|
@ -365,7 +365,7 @@ impl ConsoleQueryBarCompletionProvider {
|
||||||
new_text: string_match.string.clone(),
|
new_text: string_match.string.clone(),
|
||||||
label: CodeLabel {
|
label: CodeLabel {
|
||||||
filter_range: 0..string_match.string.len(),
|
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(),
|
runs: Vec::new(),
|
||||||
},
|
},
|
||||||
icon_path: None,
|
icon_path: None,
|
||||||
|
|
|
@ -955,7 +955,7 @@ impl ExtensionsPage {
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
configure: is_configurable.then(|| {
|
configure: is_configurable.then(|| {
|
||||||
Button::new(
|
Button::new(
|
||||||
SharedString::from(format!("configure-{}", extension.id.clone())),
|
SharedString::from(format!("configure-{}", extension.id)),
|
||||||
"Configure",
|
"Configure",
|
||||||
)
|
)
|
||||||
.disabled(true)
|
.disabled(true)
|
||||||
|
@ -980,7 +980,7 @@ impl ExtensionsPage {
|
||||||
}),
|
}),
|
||||||
configure: is_configurable.then(|| {
|
configure: is_configurable.then(|| {
|
||||||
Button::new(
|
Button::new(
|
||||||
SharedString::from(format!("configure-{}", extension.id.clone())),
|
SharedString::from(format!("configure-{}", extension.id)),
|
||||||
"Configure",
|
"Configure",
|
||||||
)
|
)
|
||||||
.on_click({
|
.on_click({
|
||||||
|
@ -1049,7 +1049,7 @@ impl ExtensionsPage {
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
configure: is_configurable.then(|| {
|
configure: is_configurable.then(|| {
|
||||||
Button::new(
|
Button::new(
|
||||||
SharedString::from(format!("configure-{}", extension.id.clone())),
|
SharedString::from(format!("configure-{}", extension.id)),
|
||||||
"Configure",
|
"Configure",
|
||||||
)
|
)
|
||||||
.disabled(true)
|
.disabled(true)
|
||||||
|
|
|
@ -354,8 +354,9 @@ impl PickerDelegate for NewPathDelegate {
|
||||||
let m = self.matches.get(self.selected_index)?;
|
let m = self.matches.get(self.selected_index)?;
|
||||||
if m.is_dir(self.project.read(cx), cx) {
|
if m.is_dir(self.project.read(cx), cx) {
|
||||||
let path = m.relative_path();
|
let path = m.relative_path();
|
||||||
self.last_selected_dir = Some(path.clone());
|
let result = format!("{}/", path);
|
||||||
Some(format!("{}/", path))
|
self.last_selected_dir = Some(path);
|
||||||
|
Some(result)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -2583,19 +2583,18 @@ impl GitPanel {
|
||||||
} else {
|
} else {
|
||||||
workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
let workspace_weak = cx.weak_entity();
|
let workspace_weak = cx.weak_entity();
|
||||||
let toast =
|
let toast = StatusToast::new(format!("git {} failed", action), cx, |this, _cx| {
|
||||||
StatusToast::new(format!("git {} failed", action.clone()), cx, |this, _cx| {
|
this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))
|
||||||
this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))
|
.action("View Log", move |window, cx| {
|
||||||
.action("View Log", move |window, cx| {
|
let message = message.clone();
|
||||||
let message = message.clone();
|
let action = action.clone();
|
||||||
let action = action.clone();
|
workspace_weak
|
||||||
workspace_weak
|
.update(cx, move |workspace, cx| {
|
||||||
.update(cx, move |workspace, cx| {
|
Self::open_output(action, workspace, &message, window, cx)
|
||||||
Self::open_output(action, workspace, &message, window, cx)
|
})
|
||||||
})
|
.ok();
|
||||||
.ok();
|
})
|
||||||
})
|
});
|
||||||
});
|
|
||||||
workspace.toggle_status_toast(toast, cx)
|
workspace.toggle_status_toast(toast, cx)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl From<ErrorCode> for anyhow::Error {
|
||||||
RpcError {
|
RpcError {
|
||||||
request: None,
|
request: None,
|
||||||
code: value,
|
code: value,
|
||||||
msg: format!("{:?}", value).to_string(),
|
msg: format!("{:?}", value),
|
||||||
tags: Default::default(),
|
tags: Default::default(),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
|
@ -241,7 +241,7 @@ impl From<ErrorCode> for RpcError {
|
||||||
RpcError {
|
RpcError {
|
||||||
request: None,
|
request: None,
|
||||||
code,
|
code,
|
||||||
msg: format!("{:?}", code).to_string(),
|
msg: format!("{:?}", code),
|
||||||
tags: Default::default(),
|
tags: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1946,9 +1946,9 @@ impl Render for ProjectSearchBar {
|
||||||
if match_quantity > 0 {
|
if match_quantity > 0 {
|
||||||
debug_assert!(match_quantity >= index);
|
debug_assert!(match_quantity >= index);
|
||||||
if limit_reached {
|
if limit_reached {
|
||||||
Some(format!("{index}/{match_quantity}+").to_string())
|
Some(format!("{index}/{match_quantity}+"))
|
||||||
} else {
|
} else {
|
||||||
Some(format!("{index}/{match_quantity}").to_string())
|
Some(format!("{index}/{match_quantity}"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -269,13 +269,12 @@ impl TerminalError {
|
||||||
Err(s) => s,
|
Err(s) => s,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| match dirs::home_dir() {
|
||||||
let default_dir =
|
Some(dir) => format!(
|
||||||
dirs::home_dir().map(|buf| buf.into_os_string().to_string_lossy().to_string());
|
"<none specified, using home directory> {}",
|
||||||
match default_dir {
|
dir.into_os_string().to_string_lossy()
|
||||||
Some(dir) => format!("<none specified, using home directory> {}", dir),
|
),
|
||||||
None => "<none specified, could not find home directory>".to_string(),
|
None => "<none specified, could not find home directory>".to_string(),
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -475,7 +475,7 @@ impl TitleBar {
|
||||||
.label_size(LabelSize::Small)
|
.label_size(LabelSize::Small)
|
||||||
.tooltip(Tooltip::text(format!(
|
.tooltip(Tooltip::text(format!(
|
||||||
"{} is sharing this project. Click to follow.",
|
"{} is sharing this project. Click to follow.",
|
||||||
host_user.github_login.clone()
|
host_user.github_login
|
||||||
)))
|
)))
|
||||||
.on_click({
|
.on_click({
|
||||||
let host_peer_id = host.peer_id;
|
let host_peer_id = host.peer_id;
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl Modal {
|
||||||
pub fn new(id: impl Into<SharedString>, scroll_handle: Option<ScrollHandle>) -> Self {
|
pub fn new(id: impl Into<SharedString>, scroll_handle: Option<ScrollHandle>) -> Self {
|
||||||
let id = id.into();
|
let id = id.into();
|
||||||
|
|
||||||
let container_id = ElementId::Name(format!("{}_container", id.clone()).into());
|
let container_id = ElementId::Name(format!("{}_container", id).into());
|
||||||
Self {
|
Self {
|
||||||
id: ElementId::Name(id),
|
id: ElementId::Name(id),
|
||||||
header: ModalHeader::new(),
|
header: ModalHeader::new(),
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl QuickActionBar {
|
||||||
|
|
||||||
let menu_state = session_state(session.clone(), cx);
|
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());
|
let element_id = |suffix| ElementId::Name(format!("{}-{}", id, suffix).into());
|
||||||
|
|
||||||
|
@ -99,8 +99,7 @@ impl QuickActionBar {
|
||||||
.child(
|
.child(
|
||||||
Label::new(format!(
|
Label::new(format!(
|
||||||
"kernel: {} ({})",
|
"kernel: {} ({})",
|
||||||
menu_state.kernel_name.clone(),
|
menu_state.kernel_name, menu_state.kernel_language
|
||||||
menu_state.kernel_language.clone()
|
|
||||||
))
|
))
|
||||||
.size(LabelSize::Small)
|
.size(LabelSize::Small)
|
||||||
.color(Color::Muted),
|
.color(Color::Muted),
|
||||||
|
@ -121,7 +120,7 @@ impl QuickActionBar {
|
||||||
menu.custom_row(move |_window, _cx| {
|
menu.custom_row(move |_window, _cx| {
|
||||||
h_flex()
|
h_flex()
|
||||||
.child(
|
.child(
|
||||||
Label::new(format!("{}...", status.clone().to_string()))
|
Label::new(format!("{}...", status.to_string()))
|
||||||
.size(LabelSize::Small)
|
.size(LabelSize::Small)
|
||||||
.color(Color::Muted),
|
.color(Color::Muted),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue