diff --git a/crates/client/src/channel_store.rs b/crates/client/src/channel_store.rs index 1beb1bc8ea..ec945ce036 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.rs index 2766cee295..c8beb86aef 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(arc: &mut Arc, 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 { type Ok;