Uh oh!
There was an error while loading. Please reload this page.
Implement Vec::splice and String::splice - #32355
Conversation
rust-highfive
commented
Mar 19, 2016
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
I’d like some other opinions here. Getting this guess wrong either way causes the tail to be moved twice.
- If we over-estimate (which it the moment only happens if
size_hintis incorrect) we reserve more space than necessary in the vector. But that space can still be used later (with further calls toVec::pushand friends).Vec::reserveoften over-allocates anyway. - If we under-estimate, we allocate a temporary vector and soon drop it.
Maybe over-estimating is better, and this should use the upper bound when it’s Some? (And fall back to the lower bound otherwise.)
There was a problem hiding this comment.
Maybe if the optimistic route is only used if Some(lower) == upper, i.e the iterator claims to know its exact size?
There was a problem hiding this comment.
If Some(lower) == upper we already use that. If they’re accurate the Vec we then collect is zero-length. The question is what to do when the two bounds are not equal?
There was a problem hiding this comment.
This condition lower_bound > 0 could be replaced by lower_bound > 0 && Some(lower_bound) == _upper_bound. Just to clarify what I mean.
There was a problem hiding this comment.
Ok, I see. In that case we’d avoid moving "tail" elements twice, but we’d allocate a temporary Vec in more cases.
SimonSapin
commented
Mar 19, 2016
It may also make sense to rewrite |
There was a problem hiding this comment.
All three fixed, thanks.
SimonSapin
commented
Mar 27, 2016
While we’re talking API (#32355 (comment)), should the |
alexcrichton
commented
Mar 28, 2016
Hm for consistency it seems like you may want that but on the other hand it seems like most of the time you'd want to splice in another slice. It's also arguably less performant as splicing a slice would require decoding and re-encoding utf-8, although perhaps we could recover the performance through specialization? This may be a good question to have open for stabilization (and the tracking issue), but doesn't necessarily seem like an immediately blocker for landing the PR. |
SimonSapin
commented
Mar 29, 2016
There is indeed the UTF-8 round-trip overhead, and also the accuracy loss of |
alexcrichton
commented
Mar 29, 2016
Hm the loss of size_hint may be killer for now, perhaps |
SimonSapin
commented
Mar 30, 2016
I’m fine with sticking to |
bors
commented
Apr 12, 2016
☔ The latest upstream changes (presumably #32804) made this pull request unmergeable. Please resolve the merge conflicts. |
alexcrichton
commented
May 8, 2016
ping @SimonSapin, any update on this? |
SimonSapin
commented
May 9, 2016
I still need to write more tests and haven’t taken the time to do it yet. If someone wants to do so before I do, feel free. |
alexcrichton
commented
May 21, 2016
Ok, in that case I'm gonna close this out of inactivity, but feel free to reopen/resubmit once the tests are there! |
solson
commented
Feb 4, 2017
@alexcrichton Is there some way we can advertise this to see if someone wants to work on it? I hate to see merged RFCs go unimplemented for so long. |
alexcrichton
commented
Feb 4, 2017
@solson an interesting idea! @rust-lang/libs, thoughts? |
glaebhoerl
commented
Feb 5, 2017
There is (or used to be?) a "help wanted" section in TWiR... |
aturon
commented
Feb 6, 2017
I added a comment to the tracking issue and marked it "help wanted", which (I think?) will lead it to TWiR (@brson?). We ultimately should do something more persistent and general, maybe on the roadmap tracker. |
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310 A rebase of rust-lang#32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310 A rebase of rust-lang#32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310 A rebase of rust-lang#32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310 A rebase of rust-lang#32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
Implement Vec::splice and String::splice (RFC 1432) RFC: rust-lang/rfcs#1432, tracking issue: #32310 A rebase of #32355 with a few more tests. Let me know if you have any ideas for more tests. cc @SimonSapin
RFC: rust-lang/rfcs#1432, tracking issue: #32310