Skip to content

Commit ee184dd

Browse files
Veykrilibraheemdev
andcommitted
Slightly cheaper get_mut
Co-authored-by: Ibraheem Ahmed <[email protected]>
1 parent 89735a2 commit ee184dd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/storage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Public API facades for the implementation details of [`Zalsa`] and [`ZalsaLocal`].
22
use std::marker::PhantomData;
3-
use std::mem;
43
use std::panic::RefUnwindSafe;
54

65
use crate::database::RawDatabase;
@@ -158,9 +157,10 @@ impl<Db: Database> Storage<Db> {
158157

159158
let mut coordinate_lock = self.handle.coordinate.coordinate_lock.lock();
160159
let zalsa = loop {
161-
if let Some(zalsa) = Arc::get_mut(&mut self.handle.zalsa_impl) {
162-
// SAFETY: Polonius when ... https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md#problem-case-3-conditional-control-flow-across-functions
163-
break unsafe { mem::transmute::<&mut Zalsa, &mut Zalsa>(zalsa) };
160+
if Arc::strong_count(&self.handle.zalsa_impl) == 1 {
161+
// SAFETY: The strong count is 1, and we never create any weak pointers,
162+
// so we have a unique reference.
163+
break unsafe { &mut *(Arc::as_ptr(&self.handle.zalsa_impl) as *mut Zalsa) };
164164
}
165165
coordinate_lock = self.handle.coordinate.cvar.wait(coordinate_lock);
166166
};

0 commit comments

Comments
 (0)