Avoid cloning entries in CollabPanel::render_signed_in

This commit is contained in:
Antonio Scandurra
2023-12-12 09:42:35 +01:00
parent a9f817fc14
commit b503edf24f
+68 -88
View File
@@ -1145,7 +1145,7 @@ impl CollabPanel {
fn render_call_participant( fn render_call_participant(
&self, &self,
user: Arc<User>, user: &Arc<User>,
peer_id: Option<PeerId>, peer_id: Option<PeerId>,
is_pending: bool, is_pending: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
@@ -2159,87 +2159,73 @@ impl CollabPanel {
.id("scroll") .id("scroll")
.overflow_y_scroll() .overflow_y_scroll()
.track_scroll(&self.scroll_handle) .track_scroll(&self.scroll_handle)
.children( .children(self.entries.iter().enumerate().map(|(ix, entry)| {
self.entries let is_selected = self.selection == Some(ix);
.clone() match entry {
.into_iter() ListEntry::Header(section) => {
.enumerate() let is_collapsed = self.collapsed_sections.contains(section);
.map(|(ix, entry)| { self.render_header(*section, is_selected, is_collapsed, cx)
let is_selected = self.selection == Some(ix); .into_any_element()
match entry { }
ListEntry::Header(section) => { ListEntry::Contact { contact, calling } => self
let is_collapsed = .render_contact(contact, *calling, is_selected, cx)
self.collapsed_sections.contains(&section); .into_any_element(),
self.render_header(section, is_selected, is_collapsed, cx) ListEntry::ContactPlaceholder => self
.into_any_element() .render_contact_placeholder(is_selected, cx)
} .into_any_element(),
ListEntry::Contact { contact, calling } => self ListEntry::IncomingRequest(user) => self
.render_contact(&*contact, calling, is_selected, cx) .render_contact_request(user, true, is_selected, cx)
.into_any_element(), .into_any_element(),
ListEntry::ContactPlaceholder => self ListEntry::OutgoingRequest(user) => self
.render_contact_placeholder(is_selected, cx) .render_contact_request(user, false, is_selected, cx)
.into_any_element(), .into_any_element(),
ListEntry::IncomingRequest(user) => self ListEntry::Channel {
.render_contact_request(user, true, is_selected, cx) channel,
.into_any_element(), depth,
ListEntry::OutgoingRequest(user) => self has_children,
.render_contact_request(user, false, is_selected, cx) } => self
.into_any_element(), .render_channel(channel, *depth, *has_children, is_selected, ix, cx)
ListEntry::Channel { .into_any_element(),
channel, ListEntry::ChannelEditor { depth } => {
depth, self.render_channel_editor(*depth, cx).into_any_element()
has_children, }
} => self ListEntry::CallParticipant {
.render_channel( user,
&*channel, peer_id,
depth, is_pending,
has_children, } => self
is_selected, .render_call_participant(user, *peer_id, *is_pending, cx)
ix, .into_any_element(),
cx, ListEntry::ParticipantProject {
) project_id,
.into_any_element(), worktree_root_names,
ListEntry::ChannelEditor { depth } => { host_user_id,
self.render_channel_editor(depth, cx).into_any_element() is_last,
} } => self
ListEntry::CallParticipant { .render_participant_project(
user, *project_id,
peer_id, &worktree_root_names,
is_pending, *host_user_id,
} => self *is_last,
.render_call_participant(user, peer_id, is_pending, cx) cx,
.into_any_element(), )
ListEntry::ParticipantProject { .into_any_element(),
project_id, ListEntry::ParticipantScreen { peer_id, is_last } => self
worktree_root_names, .render_participant_screen(*peer_id, *is_last, cx)
host_user_id, .into_any_element(),
is_last, ListEntry::ChannelNotes { channel_id } => self
} => self .render_channel_notes(*channel_id, cx)
.render_participant_project( .into_any_element(),
project_id, ListEntry::ChannelChat { channel_id } => {
&worktree_root_names, self.render_channel_chat(*channel_id, cx).into_any_element()
host_user_id, }
is_last, }
cx, })),
)
.into_any_element(),
ListEntry::ParticipantScreen { peer_id, is_last } => self
.render_participant_screen(peer_id, is_last, cx)
.into_any_element(),
ListEntry::ChannelNotes { channel_id } => {
self.render_channel_notes(channel_id, cx).into_any_element()
}
ListEntry::ChannelChat { channel_id } => {
self.render_channel_chat(channel_id, cx).into_any_element()
}
}
}),
),
) )
} }
fn render_header( fn render_header(
&mut self, &self,
section: Section, section: Section,
is_selected: bool, is_selected: bool,
is_collapsed: bool, is_collapsed: bool,
@@ -2353,14 +2339,12 @@ impl CollabPanel {
} }
fn render_contact( fn render_contact(
&mut self, &self,
contact: &Contact, contact: &Contact,
calling: bool, calling: bool,
is_selected: bool, is_selected: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> impl IntoElement { ) -> impl IntoElement {
enum ContactTooltip {}
let online = contact.online; let online = contact.online;
let busy = contact.busy || calling; let busy = contact.busy || calling;
let user_id = contact.user.id; let user_id = contact.user.id;
@@ -2426,8 +2410,8 @@ impl CollabPanel {
} }
fn render_contact_request( fn render_contact_request(
&mut self, &self,
user: Arc<User>, user: &Arc<User>,
is_incoming: bool, is_incoming: bool,
is_selected: bool, is_selected: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
@@ -2970,11 +2954,7 @@ impl CollabPanel {
// .into_any() // .into_any()
} }
fn render_channel_editor( fn render_channel_editor(&self, depth: usize, cx: &mut ViewContext<Self>) -> impl IntoElement {
&mut self,
depth: usize,
cx: &mut ViewContext<Self>,
) -> impl IntoElement {
let item = ListItem::new("channel-editor") let item = ListItem::new("channel-editor")
.inset(false) .inset(false)
.indent_level(depth) .indent_level(depth)