Skip to content

Commit fbad3b2

Browse files
authored
Switch to retain calling drain_filter.
1 parent a67749a commit fbad3b2

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/liballoc/vec.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -805,27 +805,7 @@ impl<T> Vec<T> {
805805
pub fn retain<F>(&mut self, mut f: F)
806806
where F: FnMut(&T) -> bool
807807
{
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-
unsafe {
823-
ptr::copy_nonoverlapping(src, dst, 1);
824-
}
825-
}
826-
}
827-
}
828-
self.len = len - del;
808+
self.drain_filter(|x| !f(x));
829809
}
830810

831811
/// Removes all but the first of consecutive elements in the vector that resolve to the same

0 commit comments

Comments
 (0)