-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use drop_in_place
in Vec and VecDeque
#32012
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Directly use the drop glue for [T]. Still optimizes out in -O1 like with the `needs_drop` intrinsic.
Just like for Vec. This should benefit both non-optimized and optimized performance. Non-optimized since the intrinsic drop_in_place is easily removed, and optimized because iterating the slices is more efficient than using the VecDeque iterators.
r? @gankro (rust_highfive has picked a reviewer for you, use r? to override) |
} | ||
} | ||
// use drop for [T] | ||
ptr::drop_in_place(&mut self[..]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa I had no idea this was possible, nifty!
bors
added a commit
that referenced
this pull request
Mar 3, 2016
Use `drop_in_place` in Vec and VecDeque We can use drop_in_place's DST capabilities directly in Vec::drop and similarly in VecDeque::drop. I verfied this has the same effect as the previous `needs_drop` code; `drop_in_place` it itself an intrinsic. The VecDeque replacement should be more efficient too, even in release mode (slice iteration makes a more efficient loop than the deque iterator).
mbrubeck
added a commit
to mbrubeck/rust-smallvec
that referenced
this pull request
Jun 6, 2018
This is what the standard Vec does; see rust-lang/rust#32012.
bors-servo
pushed a commit
to servo/rust-smallvec
that referenced
this pull request
Jun 6, 2018
Use a single ptr::drop_in_place call instead of a loop This is what the standard Vec does; see rust-lang/rust#32012. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/100) <!-- Reviewable:end -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
drop_in_place
in Vec and VecDequeWe can use drop_in_place's DST capabilities directly in Vec::drop and similarly in VecDeque::drop. I verfied this has the same effect as the previous
needs_drop
code;drop_in_place
it itself an intrinsic.The VecDeque replacement should be more efficient too, even in release mode (slice iteration makes a more efficient loop than the deque iterator).