-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent invalid values from existing in Vec::swap_remove
- Loading branch information
Showing
1 changed file
with
4 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
0aa68a8
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.
Is there a performance reason for putting the
set_len
after thecopy
?0aa68a8
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.
I don't think this makes any difference
0aa68a8
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.
Wouldn't
make the most sense semantically then?
or with named pointers
These avoid the in-bounds slice containing two copies of a value at any point (a condition that was introduced by this commit)
However, if there is no assumption that
ptr::copy
is (or is intended to) optimize better than aptr::read
+ptr::write
on some (potential) platform targets, this can just be reverted.0aa68a8
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.
Yes, but to be fair the code had this semantics before my PR, I just kept it. Feel free to open a PR that switches the order if this bothers you.
That's not the point. The reason I used
ptr::copy
is that it doesn't require theT
to be valid, whileptr::read
+ptr::write
does. This is a problem whenlast == hole
because in that case the read fromlast
will either be invalid or will invalidatevalue
. This was the cause of the original bug that my commit aimed to fix.0aa68a8
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.
Thank you, I found the issue/PR now.
0aa68a8
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.
Just to let you know, I just saw I made a typo in the previous comment, I meant to say "The reason I used
ptr::copy
" (now it's edited)