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

Override `StepBy::{try_fold, try_rfold}` #64121

Merged
merged 1 commit into from Sep 9, 2019

Conversation

@timvermeulen
Copy link
Contributor

commented Sep 3, 2019

Previous PR: #51435

The previous PR was closed in favor of #51601, which was later reverted. I don't think these implementations will make it harder to specialize StepBy<Range<_>> later, so we should be able to land this without any consequences.

This should fix #57517 – in my benchmarks iter and iter.step_by(1) now perform equally well, provided internal iteration is used.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Sep 3, 2019

r? @KodrAus

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

@Centril

This comment has been minimized.

Copy link
Member

commented Sep 3, 2019

@rust-highfive rust-highfive assigned scottmcm and unassigned KodrAus Sep 3, 2019

@scottmcm
Copy link
Member

left a comment

Thanks for the PR! This definitely seems like one that needs try_fold (though I wish LLVM would just peel it). One minor change and it'll be good to go.

Some(x) => acc = f(acc, x)?,
}
}
from_fn(|| self.iter.nth(self.step)).try_fold(acc, f)

This comment has been minimized.

Copy link
@scottmcm

scottmcm Sep 4, 2019

Member

Can you just use a while let Some(x) = self.iter.nth(self.step) loop here instead? It'll do the same thing, but without introducing a new closure that would regress #62429.

This comment has been minimized.

Copy link
@timvermeulen

timvermeulen Sep 4, 2019

Author Contributor

Thanks, I forgot about that. I turned the closures into functions instead, that should have the same benefits, correct? I figured this will make it easier to potentially undo these changes in the future.

@timvermeulen timvermeulen force-pushed the timvermeulen:iter_step_by_internal branch from a4d5050 to 3d62d27 Sep 4, 2019

@timvermeulen timvermeulen force-pushed the timvermeulen:iter_step_by_internal branch from 3d62d27 to 78908f2 Sep 4, 2019

@scottmcm

This comment has been minimized.

Copy link
Member

commented Sep 9, 2019

@bors r+ rollup

@bors

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

📌 Commit 78908f2 has been approved by scottmcm

Centril added a commit to Centril/rust that referenced this pull request Sep 9, 2019
Rollup merge of rust-lang#64121 - timvermeulen:iter_step_by_internal,…
… r=scottmcm

Override `StepBy::{try_fold, try_rfold}`

Previous PR: rust-lang#51435

The previous PR was closed in favor of rust-lang#51601, which was later reverted. I don't think these implementations will make it harder to specialize `StepBy<Range<_>>` later, so we should be able to land this without any consequences.

This should fix rust-lang#57517 – in my benchmarks `iter` and `iter.step_by(1)` now perform equally well, provided internal iteration is used.
@Centril Centril referenced this pull request Sep 9, 2019
bors added a commit that referenced this pull request Sep 9, 2019
Auto merge of #64313 - Centril:rollup-7w8b67g, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #63468 (Resolve attributes in several places)
 - #64121 (Override `StepBy::{try_fold, try_rfold}`)
 - #64278 (check git in bootstrap.py)
 - #64306 (Fix typo in config.toml.example)
 - #64312 (Unify escape usage)

Failed merges:

r? @ghost

@bors bors merged commit 78908f2 into rust-lang:master Sep 9, 2019

4 checks passed

pr Build #20190904.19 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 (LinuxTools) LinuxTools succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.