Skip to content

Commit

Permalink
Impl Drop for SlotTable
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jun 30, 2023
1 parent 55c62eb commit 5e74680
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/slot_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ impl SlotTable {
SlotReader::new(self)
}


pub fn into_writer(self) -> SlotWriter {
SlotWriter::new(self)
}
}



impl Drop for SlotTable {
fn drop(&mut self) {
for slot in self.slots.into_iter().copied() {
if let Some(ptr) = slot {
drop(unsafe { Box::from_raw(ptr) });
}
}
}
}
3 changes: 2 additions & 1 deletion src/slot_table/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ impl SlotWriter {
}
}

pub fn close(&mut self, table: &mut SlotTable) {
pub fn close(mut self) -> SlotTable {
self.table.groups_len = self.group_gap_start;
self.table.slots_len = self.slot_gap_start;
self.table
}

/// Begin inserting at the current location. beginInsert() can be nested and must be called with
Expand Down

0 comments on commit 5e74680

Please sign in to comment.