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:
parent
1da364e98f
commit
7ceafaee4f
1 changed files with 6 additions and 1 deletions
|
@ -70,7 +70,12 @@ impl<T: Clone> Clone for VecDeque<T> {
|
||||||
impl<T> Drop for VecDeque<T> {
|
impl<T> Drop for VecDeque<T> {
|
||||||
#[unsafe_destructor_blind_to_params]
|
#[unsafe_destructor_blind_to_params]
|
||||||
fn drop(&mut self) {
|
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
|
// RawVec handles deallocation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue