Uh oh!
There was an error while loading. Please reload this page.
specialize Extend for Vec with IntoIter - #41191
Conversation
alexcrichton
commented
Apr 10, 2017
Could this perhaps elide the unsafety by delegating to the other specialization? |
4a2f784 to
75e3607Compareseanmonstar
commented
Apr 11, 2017
@alexcrichton er, of course. Now delegating to extending from slice. |
alexcrichton
commented
Apr 11, 2017
@bors: r+ |
bors
commented
Apr 11, 2017
📌 Commit 75e3607 has been approved by |
…r, r=alexcrichton specialize Extend for Vec with IntoIter Before, `vec.extend(&other_vec)` was quite a bit faster than `vec.extend(other_vec)`. This allows extending by consuming a vec to use the same code as extending from a slice.
frewsxcv
commented
Apr 12, 2017
@bors r- Travis found an issue with this |
arielb1
commented
Apr 12, 2017
Can't this be a |
d567538 to
ade6fe3Compareseanmonstar
commented
Apr 14, 2017
@arielb1 I had assumed not, because you'd need to drop items that weren't So, I've refactored to make this make use of the same code as |
ade6fe3 to
d7b2906Comparearielb1
commented
Apr 16, 2017
r? @bluss |
bluss
left a comment
There was a problem hiding this comment.
Lgtm, memcpy is indeed what we do to move ownership of the elements from the iterator's buffer to the vec's. The request for change is basically a style issue, but I thought it was worthwhile.
There was a problem hiding this comment.
We use other here to transfer ownership of the elements, I'd be more comfortable with passing them as other: *mut [T], and it could also be even more clear in the comment that elements are moved from other; especially since elements are not dropped after actual use of the method. (No strong opinion on which *const or *mut to use.)
d7b2906 to
4d900beCompareseanmonstar
commented
Apr 17, 2017
@bluss updated to |
alexcrichton
commented
Apr 19, 2017
Looks great! Could you also add some tests which exercise this specific specialization? (and corner cases like empty vectors, zero-sized types, etc) |
4d900be to
94075c4Compareseanmonstar
commented
Apr 19, 2017
@alexcrichton there were tests for |
There was a problem hiding this comment.
This method does move elements read from other into self's allocation. It should also not talk about dropping, because no T elements need to be dropped or are dropped; they are just moved from being stored in one buffer to the other.
Can the method append_elements use an argument of type *const [T] instead? Coercions from &[T] should make that simple to call in both the calling sites.
There was a problem hiding this comment.
(Please change this comment to say that it moves the elements, or at least not say without moving, because it is moving them.)
There was a problem hiding this comment.
Updated type to *const [T].
I've changed to docs to the suggested, but the original made more sense to me. It's only half moving the elements. It has directly copied them, but the original buffer has not been modified, so if the caller doesn't do something, they'll have copied potentially uncopiable data, and have data unsafety. 🤷♂️
94075c4 to
f85a533Comparealexcrichton
commented
Apr 20, 2017
@bors: r+ |
bors
commented
Apr 20, 2017
📌 Commit f85a533 has been approved by |
bors
commented
Apr 20, 2017
…ichton specialize Extend for Vec with IntoIter Before, `vec.extend(&other_vec)` was quite a bit faster than `vec.extend(other_vec)`. This allows extending by consuming a vec to use the same code as extending from a slice.
bors
commented
Apr 20, 2017
☀️ Test successful - status-appveyor, status-travis |
Before,
vec.extend(&other_vec)was quite a bit faster thanvec.extend(other_vec). This allows extending by consuming a vec to use the same code as extending from a slice.