Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use Arc::make_mut in ChannelStore
Max Brunsfeld2605ae1ef52f
diff --git a/crates/client/src/channel_store.rs b/crates/client/src/channel_store.rsindex 1beb1bc8ea6..ec945ce0367 100644--- a/crates/client/src/channel_store.rs+++ b/crates/client/src/channel_store.rs@@ -7,7 +7,6 @@ use futures::Future;use futures::StreamExt;use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, Task};use rpc::{proto, TypedEnvelope};-use std::mem;use std::sync::Arc;pub type ChannelId = u64;@@ -319,10 +318,9 @@ impl ChannelStore {.iter_mut().find(|c| c.id == channel.id){- util::make_arc_mut(existing_channel, |new_existing_channel| {- new_existing_channel.name = channel.name;- new_existing_channel.user_is_admin = channel.user_is_admin;- });+ let existing_channel = Arc::make_mut(existing_channel);+ existing_channel.name = channel.name;+ existing_channel.user_is_admin = channel.user_is_admin;continue;}@@ -340,10 +338,9 @@ impl ChannelStore {for channel in payload.channels {if let Some(existing_channel) = self.channels.iter_mut().find(|c| c.id == channel.id) {- util::make_arc_mut(existing_channel, |new_existing_channel| {- new_existing_channel.name = channel.name;- new_existing_channel.user_is_admin = channel.user_is_admin;- });+ let existing_channel = Arc::make_mut(existing_channel);+ existing_channel.name = channel.name;+ existing_channel.user_is_admin = channel.user_is_admin;continue;}diff --git a/crates/util/src/util.rs b/crates/util/src/util.rsindex 2766cee295f..c8beb86aeff 100644--- a/crates/util/src/util.rs+++ b/crates/util/src/util.rs@@ -9,11 +9,9 @@ pub mod test;use std::{borrow::Cow,cmp::{self, Ordering},- mem,ops::{AddAssign, Range, RangeInclusive},panic::Location,pin::Pin,- sync::Arc,task::{Context, Poll},};@@ -120,19 +118,6 @@ pub fn merge_non_null_json_value_into(source: serde_json::Value, target: &mut se}}-/// Mutates through the arc if no other references exist,-/// otherwise clones the value and swaps out the reference with a new Arc-/// Useful for mutating the elements of a list while using iter_mut()-pub fn make_arc_mut<T: Clone>(arc: &mut Arc<T>, mutate: impl FnOnce(&mut T)) {- if let Some(t) = Arc::get_mut(arc) {- mutate(t);- return;- }- let mut new_t = (**arc).clone();- mutate(&mut new_t);- mem::swap(&mut Arc::new(new_t), arc);-}-pub trait ResultExt<E> {type Ok;