]> git.lizzy.rs Git - rust.git/commitdiff
Use ptr::drop_in_place in VecDeque::drop
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Wed, 2 Mar 2016 16:54:43 +0000 (17:54 +0100)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Wed, 2 Mar 2016 17:05:41 +0000 (18:05 +0100)
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.

src/libcollections/vec_deque.rs

index f34fe2da7e84b21541fab615fb79b96a25ba1d71..3e48f14d387ffff924a67849ead1881b011df078 100644 (file)
@@ -70,7 +70,12 @@ fn clone(&self) -> 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
     }
 }