@@ -67,15 +67,16 @@ impl<T: 'static + ?Sized> Deref for ArcShiftCellHandle<'_, T> {
6767}
6868
6969/// ArcShiftCell cannot be Sync, but there's nothing stopping it from being Send.
70- /// SAFETY:
71- /// As long as the contents of the cell are not !Send, it is safe to
72- /// send the cell. The object must be uniquely owned to be sent, and
73- /// this is only possible if we're not in a recursive call to
74- /// 'get'. And in this case, the properties of ArcShiftCell are the same
75- /// as ArcShift, and ArcShift is Send (if T is Send + Sync).
7670///
7771/// Note that ArcShiftCell *cannot* be Sync, because then multiple threads
7872/// could call 'get' simultaneously, corrupting the (non-atomic) refcount.
73+ // SAFETY:
74+ // As long as the contents of the cell are not !Send, it is safe to
75+ // send the cell. The object must be uniquely owned to be sent, and
76+ // this is only possible if we're not in a recursive call to
77+ // 'get'. And in this case, the properties of ArcShiftCell are the same
78+ // as ArcShift, and ArcShift is Send (if T is Send + Sync).
79+ //
7980unsafe impl < T : ' static > Send for ArcShiftCell < T > where T : Send + Sync { }
8081
8182impl < T : ' static + ?Sized > Clone for ArcShiftCell < T > {
@@ -129,6 +130,7 @@ impl<T: 'static + ?Sized> ArcShiftCell<T> {
129130 /// Make sure not to leak this handle: See further documentation on
130131 /// [`ArcShiftCellHandle`]. Leaking the handle will leak resources, but
131132 /// not cause undefined behaviour.
133+ #[ inline]
132134 pub fn borrow ( & self ) -> ArcShiftCellHandle < T > {
133135 self . recursion . set ( self . recursion . get ( ) + 1 ) ;
134136 ArcShiftCellHandle {
@@ -146,7 +148,8 @@ impl<T: 'static + ?Sized> ArcShiftCell<T> {
146148 ///
147149 /// This method is reentrant - you are allowed to call it from within the closure 'f'.
148150 /// However, only the outermost invocation will cause a reload.
149- pub fn get ( & self , f : impl FnOnce ( & T ) ) {
151+ #[ inline]
152+ pub fn get < R > ( & self , f : impl FnOnce ( & T ) -> R ) -> R {
150153 self . recursion . set ( self . recursion . get ( ) + 1 ) ;
151154 let val = if self . recursion . get ( ) == 1 {
152155 // SAFETY:
@@ -157,8 +160,9 @@ impl<T: 'static + ?Sized> ArcShiftCell<T> {
157160 // Getting the inner value is safe, no other thread can be accessing it now
158161 unsafe { & * self . inner . get ( ) } . shared_non_reloading_get ( )
159162 } ;
160- f ( val) ;
163+ let t = f ( val) ;
161164 self . recursion . set ( self . recursion . get ( ) - 1 ) ;
165+ t
162166 }
163167
164168 /// Assign the given ArcShift to this instance.
@@ -179,7 +183,7 @@ impl<T: 'static + ?Sized> ArcShiftCell<T> {
179183 }
180184 }
181185 /// Reload this ArcShiftCell-instance.
182- /// This allows dropping heap blocks kept alive by this instance of
186+ /// This allows heap blocks kept alive by this instance of
183187 /// ArcShiftCell to be dropped.
184188 /// Note, this method only works when not called from within a closure
185189 /// supplied to the 'get' method. If such recursion occurs, this method
@@ -198,7 +202,7 @@ impl<T: 'static + ?Sized> ArcShiftCell<T> {
198202 /// Create an ArcShift-instance pointing to the same data
199203 pub fn make_arcshift ( & self ) -> ArcShift < T > {
200204 // SAFETY:
201- // ArcShiftCell is not Sync, and 'reload ' does not recursively call into user
205+ // ArcShiftCell is not Sync, and 'make_arcshift ' does not recursively call into user
202206 // code, so we know no other operation can be ongoing.
203207 unsafe { & mut * self . inner . get ( ) } . clone ( )
204208 }
0 commit comments