refactor: prefer Arc<str> to String

This commit is contained in:
2026-05-23 18:45:44 +01:00
parent 1ef91cb41e
commit 1843622540
15 changed files with 524 additions and 544 deletions

View File

@@ -1,5 +1,3 @@
use std::ops::Deref;
use gpui::{
InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement, Styled, div, list,
point, prelude::FluentBuilder, px,
@@ -13,6 +11,7 @@ use crate::{
text::text,
},
query::{self, QueryStatus, read_query, use_query},
util::str::ToSharedString,
};
pub(crate) struct IssueList {
@@ -20,7 +19,6 @@ pub(crate) struct IssueList {
list_state: gpui::ListState,
list_items: Vec<IssueListItem>,
selected_item: Option<(usize, gpui::SharedString)>,
}
pub(crate) enum Event {
@@ -29,7 +27,7 @@ pub(crate) enum Event {
#[derive(gpui::IntoElement, Clone)]
pub(crate) struct IssueListItem {
id: gpui::SharedString,
id: api::issues::Id,
repo_name: Option<gpui::SharedString>,
title: gpui::SharedString,
description: Option<gpui::SharedString>,
@@ -51,7 +49,6 @@ pub(crate) fn new(cx: &mut gpui::Context<IssueList>) -> IssueList {
list_state: gpui::ListState::new(0, gpui::ListAlignment::Top, px(100.)),
list_items: Vec::new(),
selected_item: None,
};
list.on_create(cx);
list
@@ -66,16 +63,12 @@ impl IssueList {
let new_len = res.items.len();
let new_items = res.items.iter().enumerate().map(|(i, it)| IssueListItem {
id: gpui::SharedString::from(it.id.deref()),
repo_name: Some(gpui::SharedString::new(it.repo_slug.as_str())),
title: gpui::SharedString::new(it.title.as_str()),
id: it.id.clone(),
repo_name: Some(it.repo_slug.to_shared_string()),
title: it.title.to_shared_string(),
description: None,
status: it.state,
is_selected: this
.selected_item
.as_ref()
.map(|(_, id)| id.as_str() == it.id.as_str())
.unwrap_or(false),
is_selected: false,
is_last: i == new_len - 1,
is_draft: it.is_draft,
});
@@ -95,7 +88,7 @@ impl IssueList {
item.is_selected = i == j;
}
cx.notify();
cx.emit(Event::ItemSelected(item_id.as_str().into()));
cx.emit(Event::ItemSelected(item_id));
}
}
@@ -148,8 +141,8 @@ impl gpui::RenderOnce for IssueListItem {
}
let repo_name_text = match self.repo_name {
| Some(name) => text(name),
| None => text("Unknown repo"),
| Some(name) => text(name),
| None => text("Unknown repo"),
}
.text_xs()
.opacity(0.5);
@@ -162,21 +155,21 @@ impl gpui::RenderOnce for IssueListItem {
.bg(theme.colors.surface)
} else {
match self.status {
| api::issues::PullRequestState::Closed => pill(
text("Closed").text_color(theme.colors.danger_on_solid),
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.danger_on_solid),
)
.bg(theme.colors.danger_solid),
| api::issues::PullRequestState::Merged => pill(
text("Merged").text_color(theme.colors.accent_on_solid),
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.accent_on_solid),
)
.bg(theme.colors.accent_solid),
| _ => pill(
text("Open").text_color(theme.colors.success_on_solid),
font_icon(FontIcon::PullRequestArrow).text_color(theme.colors.success_on_solid),
)
.bg(theme.colors.success_solid),
| api::issues::PullRequestState::Closed => pill(
text("Closed").text_color(theme.colors.danger_on_solid),
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.danger_on_solid),
)
.bg(theme.colors.danger_solid),
| api::issues::PullRequestState::Merged => pill(
text("Merged").text_color(theme.colors.accent_on_solid),
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.accent_on_solid),
)
.bg(theme.colors.accent_solid),
| _ => pill(
text("Open").text_color(theme.colors.success_on_solid),
font_icon(FontIcon::PullRequestArrow).text_color(theme.colors.success_on_solid),
)
.bg(theme.colors.success_solid),
}
};

View File

@@ -1,3 +1,5 @@
use std::sync::Arc;
use gpui::{
AppContext, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement, Styled,
div, img, prelude::FluentBuilder,
@@ -65,7 +67,7 @@ impl PullRequestView {
let maybe_content = {
let data = read_query(&query, cx);
if let QueryStatus::Loaded(pr) = data {
Some(gpui::SharedString::new(pr.body.as_str()))
Some(Arc::clone(&pr.body))
} else {
None
}
@@ -130,8 +132,8 @@ impl PullRequestView {
}
let merge_text = pr.author.as_ref().map(|author| {
let base_branch = pr.base_branch_name.as_str();
let head_branch = pr.head_branch_name.as_str();
let base_branch = &pr.base_branch_name;
let head_branch = &pr.head_branch_name;
let str = format!(
"{} requested to merge {} into {}",
author.login, head_branch, base_branch
@@ -172,6 +174,8 @@ impl PullRequestView {
)
});
let pr_title = gpui::SharedString::new(Arc::clone(&pr.title));
let metadata_line =
div()
.flex()
@@ -184,7 +188,7 @@ impl PullRequestView {
.flex_row()
.items_center()
.gap_1p5()
.child(img(author.avatar_url.clone()).size_4().rounded_full())
.child(img(author.avatar_url.as_ref()).size_4().rounded_full())
.child(
div()
.min_w_0()
@@ -222,7 +226,7 @@ impl PullRequestView {
.flex()
.flex_col()
.items_start()
.child(text(pr.title.clone()).w_full().text_xl().mb_1())
.child(text(pr_title).w_full().text_xl().mb_1())
.child(metadata_line),
)
.child(div().flex().flex_col().items_end().gap_1().when_some(