From fc85af749339ac337b8d18d73c1b4de2a7068e64 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 13 May 2021 23:46:22 +0200 Subject: [PATCH] ProjectionArg: remove unnecessary arc --- nested/src/projection.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/nested/src/projection.rs b/nested/src/projection.rs index e6a8803..7d1e40f 100644 --- a/nested/src/projection.rs +++ b/nested/src/projection.rs @@ -52,9 +52,8 @@ impl ProjectionHelper

{ port: OuterViewPort>, notify: impl Fn(&mut P, &()) + Send + Sync + 'static ) -> Arc>>>> { - let (view, obs) = self.new_arg(notify); - port.add_observer(obs); - view + port.add_observer(self.new_arg(notify)); + port.get_view_arc() } pub fn new_sequence_arg( @@ -62,9 +61,8 @@ impl ProjectionHelper

{ port: OuterViewPort>, notify: impl Fn(&mut P, &usize) + Send + Sync + 'static ) -> Arc>>>> { - let (view, obs) = self.new_arg(notify); - port.add_observer(obs); - view + port.add_observer(self.new_arg(notify)); + port.get_view_arc() } pub fn new_index_arg( @@ -72,9 +70,8 @@ impl ProjectionHelper

{ port: OuterViewPort>, notify: impl Fn(&mut P, &Key) + Send + Sync + 'static ) -> Arc>>>> { - let (view, obs) = self.new_arg(notify); - port.add_observer(obs); - view + port.add_observer(self.new_arg(notify)); + port.get_view_arc() } pub fn new_arg< @@ -82,16 +79,13 @@ impl ProjectionHelper

{ >( &mut self, notify: impl Fn(&mut P, &V::Msg) + Send + Sync + 'static - ) -> ( - Arc>>>, - Arc>>> - ) where V::Msg: Send + Sync { + ) -> Arc>>> + where V::Msg: Send + Sync { let (tx, mut rx) = channel::>(); - let view = Arc::new(RwLock::new(None)); let arg = Arc::new(RwLock::new( ProjectionArg { - src: view.clone(), + src: None, sender: tx })); @@ -105,8 +99,8 @@ impl ProjectionHelper

{ }); self.keepalive.push(arg.clone()); - - (view, arg) + + arg } } @@ -117,7 +111,7 @@ where V: View + ?Sized, D: ChannelData, D::IntoIter: Send + Sync { - src: Arc>>>, + src: Option>, sender: ChannelSender } @@ -128,7 +122,7 @@ where D: ChannelData, D::IntoIter: Send + Sync { fn reset(&mut self, new_src: Option>>) { - *self.src.write().unwrap() = new_src; + self.src = new_src; self.notify(&()); } @@ -145,7 +139,7 @@ where D: ChannelData, { fn reset(&mut self, new_src: Option>>) { let old_len = self.src.len().unwrap_or(0); - *self.src.write().unwrap() = new_src; + self.src = new_src; let new_len = self.src.len().unwrap_or(0); self.notify_each(0 .. max(old_len, new_len)); @@ -164,7 +158,7 @@ where D: ChannelData, { fn reset(&mut self, new_src: Option>>) { let old_area = self.src.area(); - *self.src.write().unwrap() = new_src; + self.src = new_src; let new_area = self.src.area(); if let Some(area) = old_area { self.notify_each(area); }