Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply optimization from #44355 to retain #48065

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,19 @@ impl<T> Vec<T> {
for i in 0..len {
if !f(&v[i]) {
del += 1;
unsafe {
ptr::read(&v[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a call to drop_in_place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes it should. I didn't know that function existed, so thank you!

}
} 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
Expand Down