Skip to content

Commit

Permalink
use alloc_zeroed for new tables
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed May 7, 2024
1 parent ce92176 commit c515199
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/raw/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ impl<T> Table<T> {

unsafe {
let layout = Self::layout(capacity);
let ptr = alloc::alloc(layout);

// allocate the table, with the entry pointers zeroed
let ptr = alloc::alloc_zeroed(layout);

if ptr.is_null() {
alloc::handle_alloc_error(layout);
Expand All @@ -94,10 +96,6 @@ impl<T> Table<T> {
.cast::<u8>()
.write_bytes(super::meta::EMPTY, capacity);

// zero the entries table
let offset = mem::size_of::<TableLayout>() + mem::size_of::<u8>() * capacity;
ptr.add(offset).cast::<usize>().write_bytes(0, capacity);

Table {
len,
capacity,
Expand Down

0 comments on commit c515199

Please sign in to comment.