Skip to content

Commit 9b4da36

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

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
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).cast_mut()) };
164164
}
165165
coordinate_lock = self.handle.coordinate.cvar.wait(coordinate_lock);
166166
};

src/table.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ impl Table {
252252
}
253253

254254
let allocated_idx = self.push_page::<T>(ingredient, memo_types.clone());
255-
assert_eq!(allocated_idx, page_idx);
255+
assert_eq!(
256+
allocated_idx, page_idx,
257+
"allocated index does not match requested index"
258+
);
256259
}
257260
};
258261
}

src/views.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ impl Views {
108108
&self,
109109
func: fn(NonNull<Concrete>) -> NonNull<DbView>,
110110
) -> &DatabaseDownCaster<DbView> {
111-
assert_eq!(self.source_type_id, TypeId::of::<Concrete>());
111+
assert_eq!(
112+
self.source_type_id,
113+
TypeId::of::<Concrete>(),
114+
"mismatched source type"
115+
);
112116
let target_type_id = TypeId::of::<DbView>();
113117
if let Some((_, caster)) = self
114118
.view_casters

src/zalsa_local.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ impl ActiveQueryGuard<'_> {
11731173
unsafe {
11741174
self.local_state.with_query_stack_unchecked_mut(|stack| {
11751175
#[cfg(debug_assertions)]
1176-
assert_eq!(stack.len(), self.push_len);
1176+
assert_eq!(stack.len(), self.push_len, "mismatched push and pop");
11771177
let frame = stack.last_mut().unwrap();
11781178
frame.tracked_struct_ids_mut().seed(tracked_struct_ids);
11791179
})
@@ -1195,7 +1195,7 @@ impl ActiveQueryGuard<'_> {
11951195
unsafe {
11961196
self.local_state.with_query_stack_unchecked_mut(|stack| {
11971197
#[cfg(debug_assertions)]
1198-
assert_eq!(stack.len(), self.push_len);
1198+
assert_eq!(stack.len(), self.push_len, "mismatched push and pop");
11991199
let frame = stack.last_mut().unwrap();
12001200
frame.seed_iteration(durability, changed_at, edges, untracked_read, tracked_ids);
12011201
})

0 commit comments

Comments
 (0)