Skip to content

Commit 962e0b9

Browse files
authored
optimize page access (#940)
1 parent dba66f1 commit 962e0b9

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/table.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,10 @@ impl Page {
383383

384384
#[inline]
385385
fn assert_type<T: Slot>(&self) -> PageView<'_, T> {
386-
assert_eq!(
387-
self.slot_type_id,
388-
TypeId::of::<T>(),
389-
"page has slot type `{:?}` but `{:?}` was expected",
390-
self.slot_type_name,
391-
std::any::type_name::<T>(),
392-
);
386+
if self.slot_type_id != TypeId::of::<T>() {
387+
type_assert_failed::<T>(self);
388+
}
389+
393390
PageView(self, PhantomData)
394391
}
395392

@@ -403,6 +400,17 @@ impl Page {
403400
}
404401
}
405402

403+
/// This function is explicitly outlined to avoid debug machinery in the hot-path.
404+
#[cold]
405+
#[inline(never)]
406+
fn type_assert_failed<T: 'static>(page: &Page) -> ! {
407+
panic!(
408+
"page has slot type `{:?}` but `{:?}` was expected",
409+
page.slot_type_name,
410+
std::any::type_name::<T>(),
411+
)
412+
}
413+
406414
impl Drop for Page {
407415
fn drop(&mut self) {
408416
let len = *self.allocated.get_mut();

0 commit comments

Comments
 (0)