Simplify Iterator::{min, max}#59138
Merged
bors merged 5 commits intorust-lang:masterfrom Mar 13, 2019
timvermeulen:simplify_select_fold1
Merged
Simplify Iterator::{min, max}#59138bors merged 5 commits intorust-lang:masterfrom timvermeulen:simplify_select_fold1
bors merged 5 commits intorust-lang:masterfrom
timvermeulen:simplify_select_fold1
Conversation
Contributor
|
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
Member
|
Reassigning to someone on t-libs: r? @sfackler |
sfackler
reviewed
Mar 12, 2019
src/libcore/iter/traits/iterator.rs
Outdated
| // preserve stability. | ||
| |_, x, _, y| *x > *y) | ||
| .map(|(_, x)| x) | ||
| // only switch to y if it is strictly smaller, to preserve stability. |
Member
There was a problem hiding this comment.
Can we just have this delegate to min_by?
Contributor
Author
There was a problem hiding this comment.
We indeed can, I only considered forwarding to min_by_key 🙂 Thanks!
Member
|
@bors r+ Thanks! |
Collaborator
|
📌 Commit 6cc5a3d has been approved by |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR simplifies the
select_fold1helper method used to implmementIterator::{min, min_by, min_by_key, max, max_by, max_by_key}by removing the projection argument, which was only used by the implementations ofmin_by_keyandmax_by_key.I also added tests to ensure that the stability as mentioned in the comments of
minandmaxis preserved, and fixed theiter::{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.