Do not copy data before dropping

This commit is contained in:
Taiki Endo 2022-07-21 23:58:22 +09:00
parent d1218a02e0
commit 9de877f9e0
3 changed files with 8 additions and 6 deletions

View File

@ -312,8 +312,8 @@ impl<T> Drop for Bounded<T> {
// Drop the value in the slot.
let slot = &self.buffer[index];
unsafe {
let value = slot.value.get().read().assume_init();
drop(value);
let value = &mut *slot.value.get();
value.as_mut_ptr().drop_in_place();
}
}
}

View File

@ -120,8 +120,10 @@ impl<T> Drop for Single<T> {
fn drop(&mut self) {
// Drop the value in the slot.
if *self.state.get_mut() & PUSHED != 0 {
let value = unsafe { self.slot.get().read().assume_init() };
drop(value);
unsafe {
let value = &mut *self.slot.get();
value.as_mut_ptr().drop_in_place();
}
}
}
}

View File

@ -387,8 +387,8 @@ impl<T> Drop for Unbounded<T> {
if offset < BLOCK_CAP {
// Drop the value in the slot.
let slot = (*block).slots.get_unchecked(offset);
let value = slot.value.get().read().assume_init();
drop(value);
let value = &mut *slot.value.get();
value.as_mut_ptr().drop_in_place();
} else {
// Deallocate the block and move to the next one.
let next = *(*block).next.get_mut();