Apply optimization from #44355 to retain
This commit is contained in:
parent
fee39ba8bd
commit
2a4c018518
1 changed files with 9 additions and 4 deletions
|
|
@ -813,14 +813,19 @@ impl<T> Vec<T> {
|
|||
for i in 0..len {
|
||||
if !f(&v[i]) {
|
||||
del += 1;
|
||||
unsafe {
|
||||
ptr::read(&v[i]);
|
||||
}
|
||||
} else if del > 0 {
|
||||
v.swap(i - del, i);
|
||||
let src: *const T = &v[i];
|
||||
let dst: *mut T = &mut v[i - del];
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(src, dst, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if del > 0 {
|
||||
self.truncate(len - del);
|
||||
}
|
||||
self.len = len - del;
|
||||
}
|
||||
|
||||
/// 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