Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Abuse a closure instead of abusing options/iterators quite so much
Julia33c265d3cf26
diff --git a/crates/call/src/room.rs b/crates/call/src/room.rsindex d3d7facf3b5..2f4fd56e470 100644--- a/crates/call/src/room.rs+++ b/crates/call/src/room.rs@@ -459,10 +459,10 @@ impl Room {self.participant_user_ids.contains(&user_id)}- pub fn follows(&self, leader_id: PeerId) -> &[PeerId] {+ pub fn follows(&self, leader_id: PeerId) -> Option<&[PeerId]> {self.follows_by_leader_id.get(&leader_id)- .map_or(&[], |v| v.as_slice())+ .map(|v| v.as_slice())}async fn handle_room_updated(diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rsindex 518df161694..f9b8df34885 100644--- a/crates/collab_ui/src/collab_titlebar_item.rs+++ b/crates/collab_ui/src/collab_titlebar_item.rs@@ -569,11 +569,6 @@ impl CollabTitlebarItem {workspace.read(cx).is_following(peer_id)});- let room = ActiveCall::global(cx).read(cx).room();- let get_followers = |leader_id: PeerId| -> &[PeerId] {- room.map_or(&[], |room| room.read(cx).follows(leader_id))- };-let mut avatar_style;if let Some((_, location)) = peer_id_and_location {if let ParticipantLocation::SharedProject { project_id } = location {@@ -603,31 +598,21 @@ impl CollabTitlebarItem {Flex::row().with_child(Self::render_face(avatar.clone(), avatar_style, theme)).with_children(- peer_id_and_location- .map(|(peer_id, _)| {- get_followers(peer_id)- .into_iter()- .map(|&follower| {- room.map(|room| {- room.read(cx)- .remote_participant_for_peer_id(follower)- .map(|participant| {- participant.user.avatar.as_ref().map(|avatar| {- Self::render_face(- avatar.clone(),- avatar_style,- theme,- )- })- })- .flatten()- })- .flatten()- })- .flatten()- })- .into_iter()- .flatten(),+ (|| {+ let peer_id_and_location = peer_id_and_location?;+ let peer_id = peer_id_and_location.0;++ let room = ActiveCall::global(cx).read(cx).room()?.read(cx);+ let followers = room.follows(peer_id)?;++ Some(followers.into_iter().flat_map(|&follower| {+ let participant = room.remote_participant_for_peer_id(follower)?;+ let avatar = participant.user.avatar.as_ref()?;+ Some(Self::render_face(avatar.clone(), avatar_style, theme))+ }))+ })()+ .into_iter()+ .flatten(),).with_reversed_paint_order().boxed()