about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorJacob Kiesel <kieseljake@gmail.com>2018-02-07 12:35:52 -0700
committerJacob Kiesel <kieseljake@gmail.com>2018-02-07 21:23:16 -0700
commit2a4c0185187dd40683697932c57af608062cb320 (patch)
tree074be3855549c2363ec58499b17fce139f14b960 /src/liballoc
parentfee39ba8bd98f5b93c60de51336830fa7f0b9d97 (diff)
downloadrust-2a4c0185187dd40683697932c57af608062cb320.tar.gz
rust-2a4c0185187dd40683697932c57af608062cb320.zip
Apply optimization from #44355 to retain
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index b26979c7f6d..a906628dbc7 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -813,14 +813,19 @@ impl<T> Vec<T> {
             for i in 0..len {
                 if !f(&v[i]) {
                     del += 1;
+                    unsafe {
+                        ptr::read(&v[i]);
+                    }
                 } else if del > 0 {
-                    v.swap(i - del, i);
+                    let src: *const T = &v[i];
+                    let dst: *mut T = &mut v[i - del];
+                    unsafe {
+                        ptr::copy_nonoverlapping(src, dst, 1);
+                    }
                 }
             }
         }
-        if del > 0 {
-            self.truncate(len - del);
-        }
+        self.len = len - del;
     }
 
     /// Removes all but the first of consecutive elements in the vector that resolve to the same