Skip to content

Commit 7ceafae

Browse files
committed
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.
1 parent 1da364e commit 7ceafae

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libcollections/vec_deque.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ impl<T: Clone> Clone for VecDeque<T> {
7070
impl<T> Drop for VecDeque<T> {
7171
#[unsafe_destructor_blind_to_params]
7272
fn drop(&mut self) {
73-
self.clear();
73+
let (front, back) = self.as_mut_slices();
74+
unsafe {
75+
// use drop for [T]
76+
ptr::drop_in_place(front);
77+
ptr::drop_in_place(back);
78+
}
7479
// RawVec handles deallocation
7580
}
7681
}

0 commit comments

Comments
 (0)