]> git.lizzy.rs Git - rust.git/commitdiff
Switch to retain calling drain_filter.
authorJacob Kiesel <kieseljake@gmail.com>
Tue, 13 Feb 2018 15:48:25 +0000 (08:48 -0700)
committerGitHub <noreply@github.com>
Tue, 13 Feb 2018 15:48:25 +0000 (08:48 -0700)
src/liballoc/vec.rs

index 41ba8e12105bbe0f3d8bafd989ab5fc7fc1953a2..5c7f8ef73217f62141e5afb84998a98b4db0b0cc 100644 (file)
@@ -805,27 +805,7 @@ pub fn remove(&mut self, index: usize) -> T {
     pub fn retain<F>(&mut self, mut f: F)
         where F: FnMut(&T) -> bool
     {
-        let len = self.len();
-        let mut del = 0;
-        {
-            let v = &mut **self;
-
-            for i in 0..len {
-                if !f(&v[i]) {
-                    del += 1;
-                    unsafe {
-                        ptr::drop_in_place(&mut v[i]);
-                    }
-                } else if del > 0 {
-                    let src: *const T = &v[i];
-                    let dst: *mut T = &mut v[i - del];
-                    unsafe {
-                        ptr::copy_nonoverlapping(src, dst, 1);
-                    }
-                }
-            }
-        }
-        self.len = len - del;
+        self.drain_filter(|x| !f(x));
     }
 
     /// Removes all but the first of consecutive elements in the vector that resolve to the same