]> git.lizzy.rs Git - rust.git/commitdiff
Don't drop values in other, just move the tail
authorPazzaz <pazzaz.sundqvist@gmail.com>
Tue, 14 Aug 2018 18:54:25 +0000 (20:54 +0200)
committerPazzaz <pazzaz.sundqvist@gmail.com>
Tue, 14 Aug 2018 18:54:25 +0000 (20:54 +0200)
src/liballoc/collections/vec_deque.rs

index 7f4fbb99c22d6347c63a314a52ba312ebbc457e6..b66bb82bc37b59f2383ab753e73bff3c8e3abd0c 100644 (file)
@@ -1859,7 +1859,7 @@ unsafe fn copy_whole_slice<T>(src_slice: &[T], dst_slice: &mut [T]) {
         // Guarantees there is space in `self` for `other`.
         self.reserve(src_total);
 
-        let new_head = {
+        self.head = {
             let original_head = self.head;
 
             // The goal is to copy all values from `other` into `self`. To avoid any
@@ -1988,12 +1988,8 @@ unsafe fn copy_whole_slice<T>(src_slice: &[T], dst_slice: &mut [T]) {
             }
         };
 
-        // Up until this point we are in a bad state as some values
-        // exist in both `self` and `other`. To preserve panic safety
-        // it is important we clear the old values from `other`...
-        other.clear();
-        // and that we update `head` as the last step, making the values accessible in `self`.
-        self.head = new_head;
+        // Some values now exist in both `other` and `self` but are made inaccessible in `other`.
+        other.tail = other.head;
     }
 
     /// Retains only the elements specified by the predicate.