-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Shortcuts for min/max on ordinary BTreeMap/BTreeSet iterators #73627
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Could you provide a summary of the affected impls and which ones are left out of scope? |
a85b66c
to
42062a5
Compare
I couldn't come up with a reasonable reason to leave some of them out, so added some more. Also straightened out the test code. |
Okay, that set of iterators does look correct to me. However, I think the implementation here is a bit wrong if we want to avoid a behavior change. In particular, this makes One downside (or upside, I guess) of the current implementation is that you can call |
For a generic iterator, we do need min() and max() to advance past every element of the iterator, but since these iterators are specific ones where iteration does not have a side effect the change isn't observable. min() and max() consume the iterator by value, so you can't call them multiple times. |
Ah for some reason I thought by_ref() let you magically have ownership but that doesn't make any sense now that I think about it some more. Yes, this seems fine then. @bors r+ |
📌 Commit 42062a5 has been approved by |
…Simulacrum Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators Closes rust-lang#59947: a performance tweak that might benefit some. Optimizes `min` and `max ` on all btree double-ended iterators that do not drop, i.e. the iterators created by: - `BTreeMap::iter` - `BTreeMap::iter_mut` - `BTreeMap::keys` and `BTreeSet::iter` - `BTreeMap::range` and `BTreeSet::range` - `BTreeMap::range_mut` Also in these (currently) single-ended iterators, but obviously for `min` only: - `BTreeSet::difference` - `BTreeSet::intersection` - `BTreeSet::symmetric_difference` - `BTreeSet::union` Did not do this in iterators created by `into_iter` to preserve drop order, as outlined in rust-lang#62316. Did not do this in iterators created by `drain_filter`, possibly to preserve drop order, possibly to preserve predicate invocation, mostly to not have to think about it too hard (I guess maybe it wouldn't be a change for `min`, which is the only shortcut possible in this single-ended iterator).
…Simulacrum Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators Closes rust-lang#59947: a performance tweak that might benefit some. Optimizes `min` and `max ` on all btree double-ended iterators that do not drop, i.e. the iterators created by: - `BTreeMap::iter` - `BTreeMap::iter_mut` - `BTreeMap::keys` and `BTreeSet::iter` - `BTreeMap::range` and `BTreeSet::range` - `BTreeMap::range_mut` Also in these (currently) single-ended iterators, but obviously for `min` only: - `BTreeSet::difference` - `BTreeSet::intersection` - `BTreeSet::symmetric_difference` - `BTreeSet::union` Did not do this in iterators created by `into_iter` to preserve drop order, as outlined in rust-lang#62316. Did not do this in iterators created by `drain_filter`, possibly to preserve drop order, possibly to preserve predicate invocation, mostly to not have to think about it too hard (I guess maybe it wouldn't be a change for `min`, which is the only shortcut possible in this single-ended iterator).
…Simulacrum Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators Closes rust-lang#59947: a performance tweak that might benefit some. Optimizes `min` and `max ` on all btree double-ended iterators that do not drop, i.e. the iterators created by: - `BTreeMap::iter` - `BTreeMap::iter_mut` - `BTreeMap::keys` and `BTreeSet::iter` - `BTreeMap::range` and `BTreeSet::range` - `BTreeMap::range_mut` Also in these (currently) single-ended iterators, but obviously for `min` only: - `BTreeSet::difference` - `BTreeSet::intersection` - `BTreeSet::symmetric_difference` - `BTreeSet::union` Did not do this in iterators created by `into_iter` to preserve drop order, as outlined in rust-lang#62316. Did not do this in iterators created by `drain_filter`, possibly to preserve drop order, possibly to preserve predicate invocation, mostly to not have to think about it too hard (I guess maybe it wouldn't be a change for `min`, which is the only shortcut possible in this single-ended iterator).
…arth Rollup of 12 pull requests Successful merges: - rust-lang#72771 (Warn if linking to a private item) - rust-lang#72937 (Fortanix SGX target libunwind build process changes) - rust-lang#73485 (Perform obligation deduplication to avoid buggy `ExistentialMismatch`) - rust-lang#73529 (Add liballoc impl SpecFromElem for i8) - rust-lang#73579 (add missing doc links) - rust-lang#73627 (Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators) - rust-lang#73691 (Bootstrap: detect Windows based on sys.platform) - rust-lang#73694 (Document the Self keyword) - rust-lang#73718 (Document the super keyword) - rust-lang#73728 (Document some invariants correctly/more) - rust-lang#73738 (Remove irrelevant comment) - rust-lang#73765 (Remove blank line) Failed merges: r? @ghost
I think this PR caused a regression: #73915 |
Closes #59947: a performance tweak that might benefit some. Optimizes
min
andmax
on all btree double-ended iterators that do not drop, i.e. the iterators created by:BTreeMap::iter
BTreeMap::iter_mut
BTreeMap::keys
andBTreeSet::iter
BTreeMap::range
andBTreeSet::range
BTreeMap::range_mut
Also in these (currently) single-ended iterators, but obviously for
min
only:BTreeSet::difference
BTreeSet::intersection
BTreeSet::symmetric_difference
BTreeSet::union
Did not do this in iterators created by
into_iter
to preserve drop order, as outlined in #62316.Did not do this in iterators created by
drain_filter
, possibly to preserve drop order, possibly to preserve predicate invocation, mostly to not have to think about it too hard (I guess maybe it wouldn't be a change formin
, which is the only shortcut possible in this single-ended iterator).