1
Fork 0

Use ptr::drop_in_place in VecDeque::drop

Just like for Vec. This should benefit both non-optimized and optimized
performance. Non-optimized since the intrinsic drop_in_place is easily
removed, and optimized because iterating the slices is more efficient
than using the VecDeque iterators.
This commit is contained in:
Ulrik Sverdrup 2016-03-02 17:54:43 +01:00
parent 1da364e98f
commit 7ceafaee4f

View file

@ -70,7 +70,12 @@ impl<T: Clone> Clone for VecDeque<T> {
impl<T> Drop for VecDeque<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
self.clear();
let (front, back) = self.as_mut_slices();
unsafe {
// use drop for [T]
ptr::drop_in_place(front);
ptr::drop_in_place(back);
}
// RawVec handles deallocation
}
}