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

Match `VecDeque::extend` to `Vec::extend_desugared` #66341

Merged
merged 1 commit into from Dec 13, 2019

Conversation

@crgl
Copy link
Contributor

crgl commented Nov 12, 2019

Currently, VecDeque::extend does not reserve at all. This implementation still runs a check every iteration of the loop, but should reallocate at most once for the common cases where the size_hint lower bound is exact. Further optimizations in the future could improve this for some common cases, but given the complexity of the Vec::extend implementation it's not immediately clear that this would be worthwhile.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 12, 2019

r? @Kimundi

(rust_highfive has picked a reviewer for you, use r? to override)

@crgl crgl force-pushed the crgl:vec-deque-extend branch from 1824aea to 164d1a2 Nov 13, 2019
@joelpalmer

This comment has been minimized.

Copy link

joelpalmer commented Nov 18, 2019

Ping from Triage: Any update? @hellow554 @Kimundi?

@Dylan-DPC

This comment has been minimized.

Copy link
Member

Dylan-DPC commented Nov 22, 2019

@rust-highfive rust-highfive assigned SimonSapin and unassigned Kimundi Nov 22, 2019
@ProgrammaticNajel

This comment has been minimized.

Copy link

ProgrammaticNajel commented Nov 29, 2019

Ping from triage

@SimonSapin any updates on this? Thanks.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Nov 29, 2019

Sorry. I’m not familiar enough with internals of VecDeque to know off-hand if this direct manipulation of self.head is correct, and without benchmarks to show whether this is actually an improvement I don’t know if it’s worth spending the time to read up all of VecDeque to learn how it works. Also, I’ve removed myself from the review auto-assignment because of limited bandwidth. Unless you’re confident that I have experience on something that another reviewer won’t, please consider asking other people for reviews.

r? @Dylan-DPC

@Dylan-DPC

This comment has been minimized.

Copy link
Member

Dylan-DPC commented Dec 5, 2019

@rust-highfive rust-highfive assigned dtolnay and unassigned Dylan-DPC Dec 5, 2019
@Dylan-DPC

This comment has been minimized.

Copy link
Member

Dylan-DPC commented Dec 12, 2019

@rust-highfive rust-highfive assigned Amanieu and unassigned dtolnay Dec 12, 2019
@Amanieu

This comment has been minimized.

Copy link
Contributor

Amanieu commented Dec 12, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 12, 2019

📌 Commit 164d1a2 has been approved by Amanieu

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 13, 2019

⌛️ Testing commit 164d1a2 with merge 6c6235d...

bors added a commit that referenced this pull request Dec 13, 2019
Match `VecDeque::extend` to `Vec::extend_desugared`

Currently, `VecDeque::extend` [does not reserve at all](#65069 (comment)). This implementation still runs a check every iteration of the loop, but should reallocate at most once for the common cases where the `size_hint` lower bound is exact. Further optimizations in the future could improve this for some common cases, but given the complexity of the `Vec::extend` implementation it's not immediately clear that this would be worthwhile.
Centril added a commit to Centril/rust that referenced this pull request Dec 13, 2019
Match `VecDeque::extend` to `Vec::extend_desugared`

Currently, `VecDeque::extend` [does not reserve at all](rust-lang#65069 (comment)). This implementation still runs a check every iteration of the loop, but should reallocate at most once for the common cases where the `size_hint` lower bound is exact. Further optimizations in the future could improve this for some common cases, but given the complexity of the `Vec::extend` implementation it's not immediately clear that this would be worthwhile.
@Centril

This comment has been minimized.

Copy link
Member

Centril commented Dec 13, 2019

@bors retry rolled up.

bors added a commit that referenced this pull request Dec 13, 2019
Rollup of 6 pull requests

Successful merges:

 - #66341 (Match `VecDeque::extend` to `Vec::extend_desugared`)
 - #67243 (LinkedList: drop remaining items when drop panics)
 - #67247 (Don't suggest wrong snippet in closure)
 - #67250 (Remove the `DelimSpan` from `NamedMatch::MatchedSeq`.)
 - #67251 (Require `allow_internal_unstable` for stable min_const_fn using unsta…)
 - #67269 (parser: recover on `&'lifetime mut? $pat`.)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 13, 2019

⌛️ Testing commit 164d1a2 with merge cf7e019...

@bors bors merged commit 164d1a2 into rust-lang:master Dec 13, 2019
4 of 5 checks passed
4 of 5 checks passed
homu Testing commit 164d1a205d21e0bc54b60cb4e9badf27b3883ffd with merge cf7e019b42cd523d91cb350ab49acbda1b11e571...
Details
pr Build #20191113.34 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@crgl crgl deleted the crgl:vec-deque-extend branch Dec 13, 2019
// }
let mut iter = iter.into_iter();
while let Some(element) = iter.next() {
if self.len() == self.capacity() {

This comment has been minimized.

Copy link
@Lonami

Lonami Dec 19, 2019

This implementation still runs a check every iteration of the loop

Wouldn't it be possible to move this out of the loop?

let capacity = self.capacity() - self.len();
let (lower, _) = iter.size_hint();
if capacity < lower {
    self.reserve(...);
}

This comment has been minimized.

Copy link
@crgl

crgl Jan 6, 2020

Author Contributor

You could do it for trusted length iterators specifically, but otherwise because it's a lower bound you have to check every time. At some point it could be good to specialize, though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.