Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,10 @@ impl Page {

#[inline]
fn assert_type<T: Slot>(&self) -> PageView<'_, T> {
assert_eq!(
self.slot_type_id,
TypeId::of::<T>(),
"page has slot type `{:?}` but `{:?}` was expected",
self.slot_type_name,
std::any::type_name::<T>(),
);
if self.slot_type_id != TypeId::of::<T>() {
type_assert_failed::<T>(self);
}

PageView(self, PhantomData)
}

Expand All @@ -403,6 +400,17 @@ impl Page {
}
}

/// This function is explicitly outlined to avoid debug machinery in the hot-path.
#[cold]
#[inline(never)]
fn type_assert_failed<T: 'static>(page: &Page) -> ! {
panic!(
"page has slot type `{:?}` but `{:?}` was expected",
page.slot_type_name,
std::any::type_name::<T>(),
)
}

impl Drop for Page {
fn drop(&mut self) {
let len = *self.allocated.get_mut();
Expand Down