Skip to content

Commit

Permalink
Use boxed array in HeapPage
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Aug 9, 2024
1 parent dc155a3 commit 3507757
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ const HEAP_PAGE_SIZE: usize = 1 << 12;

/// Heap page.
#[derive(Debug, Clone, PartialEq)]
struct HeapPage(Box<[u8]>);
struct HeapPage(Box<[u8; HEAP_PAGE_SIZE]>);

impl Default for HeapPage {
fn default() -> Self {
Self(vec![0_u8; HEAP_PAGE_SIZE].into())
let boxed_slice: Box<[u8]> = vec![0_u8; HEAP_PAGE_SIZE].into();
Self(boxed_slice.try_into().unwrap()) // FIXME: bench `unwrap_unchecked()`?
}
}

Expand All @@ -48,7 +49,7 @@ impl Heap {
} else {
let mut boxed_slice: Box<[u8]> = vec![0_u8; HEAP_PAGE_SIZE].into();
boxed_slice[..bytes.len()].copy_from_slice(bytes);
HeapPage(boxed_slice)
HeapPage(boxed_slice.try_into().unwrap())
})
})
.collect();
Expand Down

0 comments on commit 3507757

Please sign in to comment.