about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorJacob Kiesel <kieseljake@gmail.com>2018-02-13 08:48:25 -0700
committerGitHub <noreply@github.com>2018-02-13 08:48:25 -0700
commitfbad3b2468f46c14d0fd1283aa4935b3d79f007b (patch)
tree01ce9f4438037cd3c8994cf2476e75aac30b6eb4 /src/liballoc
parenta67749ae87b1c873ed09fca2a204beff2fe5e7ea (diff)
downloadrust-fbad3b2468f46c14d0fd1283aa4935b3d79f007b.tar.gz
rust-fbad3b2468f46c14d0fd1283aa4935b3d79f007b.zip
Switch to retain calling drain_filter.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec.rs22
1 files changed, 1 insertions, 21 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 41ba8e12105..5c7f8ef7321 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -805,27 +805,7 @@ impl<T> Vec<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