Skip to content
Open
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
15 changes: 10 additions & 5 deletions src/bbbul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Node {

#[allow(clippy::mut_from_ref)]
fn new_in(block_size: usize, bump: &Bump) -> &mut Node {
check_node_base_size();
let total_size = Self::BASE_SIZE + block_size;
let align = mem::align_of::<Option<NonNull<Node>>>();
let layout = Layout::from_size_align(total_size, align).unwrap();
Expand All @@ -92,6 +93,15 @@ impl Node {
}
}

fn check_node_base_size() {
let size = Node::BASE_SIZE;
debug_assert!(
size == 16,
"⚠️ Node::BASE_SIZE is {}, but expected 16 — check architecture assumptions",
size
);
}

impl<'bump, B: BitPacker> Bbbul<'bump, B> {
/// Construct a new `Bbbul` type.
pub fn new_in(bump: &'bump Bump) -> Bbbul<'bump, B> {
Expand Down Expand Up @@ -295,11 +305,6 @@ unsafe fn fatten(data: NonNull<u8>, len: usize) -> *mut Node {
ptr::slice_from_raw_parts_mut(data.as_ptr(), len) as *mut Node
}

/// Make sure that Node base size has a size of 16 bytes.
const _NODE_SIZE_16: () = if Node::BASE_SIZE != 16 {
unreachable!()
};

/// Make sure that Bbbul does not need drop.
const _BBBUL_NEEDS_DROP: () = if needs_drop::<Bbbul<bitpacking::BitPacker4x>>() {
unreachable!()
Expand Down