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 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
Copy link
Collaborator

r? @Kimundi

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 12, 2019
@joelpalmer
Copy link

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

@Dylan-DPC-zz
Copy link

r? @SimonSapin

@rust-highfive rust-highfive assigned SimonSapin and unassigned Kimundi Nov 22, 2019
@wirelessringo
Copy link

Ping from triage

@SimonSapin any updates on this? Thanks.

@SimonSapin
Copy link
Contributor

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-zz
Copy link

r? @dtolnay

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

r? @Amanieu

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

Amanieu commented Dec 12, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Dec 12, 2019

📌 Commit 164d1a2 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2019
@bors
Copy link
Contributor

bors commented Dec 13, 2019

⌛ Testing commit 164d1a2 with merge 6c6235d30d605fa38b55d059a8c57b3e1149885b...

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
Copy link
Contributor

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
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
@crgl crgl deleted the vec-deque-extend branch December 13, 2019 07:34
// }
let mut iter = iter.into_iter();
while let Some(element) = iter.next() {
if self.len() == self.capacity() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.