diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index b26979c7f6d8c..5c7f8ef73217f 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -805,22 +805,7 @@ impl Vec { pub fn retain(&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; - } else if del > 0 { - v.swap(i - del, i); - } - } - } - if del > 0 { - self.truncate(len - del); - } + self.drain_filter(|x| !f(x)); } /// Removes all but the first of consecutive elements in the vector that resolve to the same