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.
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
}
}