Switch to retain calling drain_filter.
This commit is contained in:
parent
a67749ae87
commit
fbad3b2468
1 changed files with 1 additions and 21 deletions
|
@ -805,27 +805,7 @@ impl<T> Vec<T> {
|
||||||
pub fn retain<F>(&mut self, mut f: F)
|
pub fn retain<F>(&mut self, mut f: F)
|
||||||
where F: FnMut(&T) -> bool
|
where F: FnMut(&T) -> bool
|
||||||
{
|
{
|
||||||
let len = self.len();
|
self.drain_filter(|x| !f(x));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all but the first of consecutive elements in the vector that resolve to the same
|
/// Removes all but the first of consecutive elements in the vector that resolve to the same
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue