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

Simplify Iterator::{min, max} #59138

Merged
merged 5 commits into from
Mar 13, 2019
Merged

Simplify Iterator::{min, max} #59138

merged 5 commits into from
Mar 13, 2019

Conversation

timvermeulen
Copy link
Contributor

This PR simplifies the select_fold1 helper method used to implmement Iterator::{min, min_by, min_by_key, max, max_by, max_by_key} by removing the projection argument, which was only used by the implementations of min_by_key and max_by_key.

I also added tests to ensure that the stability as mentioned in the comments of min and max is preserved, and fixed the iter::{bench_max, bench_max_by_key} benchmarks which the compiler presumably was able to collapse into closed-form expressions. None of the benchmark results were impacted, I suspect their generated assembly didn't change.

@rust-highfive
Copy link
Collaborator

r? @cramertj

(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 Mar 12, 2019
@cramertj
Copy link
Member

Reassigning to someone on t-libs:

r? @sfackler

@rust-highfive rust-highfive assigned sfackler and unassigned cramertj Mar 12, 2019
// preserve stability.
|_, x, _, y| *x > *y)
.map(|(_, x)| x)
// only switch to y if it is strictly smaller, to preserve stability.
Copy link
Member

Choose a reason for hiding this comment

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

Can we just have this delegate to min_by?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We indeed can, I only considered forwarding to min_by_key 🙂 Thanks!

@sfackler
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Mar 12, 2019

📌 Commit 6cc5a3d has been approved by sfackler

@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 Mar 12, 2019
Centril added a commit to Centril/rust that referenced this pull request Mar 13, 2019
… r=sfackler

Simplify Iterator::{min, max}

This PR simplifies the `select_fold1` helper method used to implmement `Iterator::{min, min_by, min_by_key, max, max_by, max_by_key}` by removing the projection argument, which was only used by the implementations of `min_by_key` and `max_by_key`.

I also added tests to ensure that the stability as mentioned in the comments of `min` and `max` is preserved, and fixed the `iter::{bench_max, bench_max_by_key}` benchmarks which the compiler presumably was able to collapse into closed-form expressions. None of the benchmark results were impacted, I suspect their generated assembly didn't change.
bors added a commit that referenced this pull request Mar 13, 2019
Rollup of 16 pull requests

Successful merges:

 - #58829 (librustc_interface: Update scoped-tls to 1.0)
 - #58876 (Parse lifetimes that start with a number and give specific error)
 - #58908 (Update rand version)
 - #58998 (Fix documentation of from_ne_bytes and from_le_bytes)
 - #59056 (Use lifetime contravariance to elide more lifetimes in core+alloc+std)
 - #59057 (Standardize `Range*` documentation)
 - #59080 (Fix incorrect links in librustc_codegen_llvm documentation)
 - #59083 (Fix #54822 and associated faulty tests)
 - #59093 (Remove precompute_in_scope_traits_hashes)
 - #59101 (Reduces Code Repetitions like `!n >> amt`)
 - #59121 (impl FromIterator for Result: Use assert_eq! instead of assert!)
 - #59124 (Replace assert with assert_eq)
 - #59129 (Visit impl Trait for dead_code lint)
 - #59130 (Note that NonNull does not launder shared references for mutation)
 - #59132 (ignore higher-ranked object bound conditions created by WF)
 - #59138 (Simplify Iterator::{min, max})

Failed merges:

r? @ghost
@bors bors merged commit 6cc5a3d into rust-lang:master Mar 13, 2019
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.

5 participants