We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a67749a commit fbad3b2Copy full SHA for fbad3b2
src/liballoc/vec.rs
@@ -805,27 +805,7 @@ impl<T> Vec<T> {
805
pub fn retain<F>(&mut self, mut f: F)
806
where F: FnMut(&T) -> bool
807
{
808
- let len = self.len();
809
- let mut del = 0;
810
- {
811
- let v = &mut **self;
812
-
813
- for i in 0..len {
814
- if !f(&v[i]) {
815
- del += 1;
816
- unsafe {
817
- ptr::drop_in_place(&mut v[i]);
818
- }
819
- } else if del > 0 {
820
- let src: *const T = &v[i];
821
- let dst: *mut T = &mut v[i - del];
822
823
- ptr::copy_nonoverlapping(src, dst, 1);
824
825
826
827
828
- self.len = len - del;
+ self.drain_filter(|x| !f(x));
829
}
830
831
/// Removes all but the first of consecutive elements in the vector that resolve to the same
0 commit comments