-
Notifications
You must be signed in to change notification settings - Fork 14k
btree: cleanup difference, intersection, is_subset #147808
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
Conversation
|
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
This comment has been minimized.
This comment has been minimized.
8e45e8f to
87755a7
Compare
This comment has been minimized.
This comment has been minimized.
87755a7 to
31807b6
Compare
This comment has been minimized.
This comment has been minimized.
31807b6 to
c6181f6
Compare
This comment has been minimized.
This comment has been minimized.
c6181f6 to
5b3bd95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is much cleaner, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please omit the changes not related to alloc from this PR – if something breaks here, doing them in a batch makes bisecting really difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
| match self_min.cmp(other_min) { | ||
| Less => return false, | ||
| Equal => self_iter.next(), | ||
| Greater => None, | ||
| }; | ||
| let (other_min, other_max) = | ||
| if let (Some(other_min), Some(other_max)) = (other.first(), other.last()) { | ||
| (other_min, other_max) | ||
| } else { | ||
| return false; // other is empty | ||
| match self_max.cmp(other_max) { | ||
| Greater => return false, | ||
| Equal => self_iter.next_back(), | ||
| Less => None, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these values are never used, I find the None arms very confusing, so I wouldn't change this. But a comment on the next calls explaining that they remove self_min/self_max from the iteration wouldn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| // skip over elements that are smaller | ||
| // happens up to `ITER_PERFORMANCE_TIPPING_SIZE_DIFF * self.len() - 1` times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find the "happens n times" notes to be particularly helpful – it'd be better to have the comments explain why the action chosen is the right one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments explain why this ordering is used (from most frequent to least frequent), but I'll see about adding some comments explaining correctness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added those comments.
| Greater => (), | ||
| } | ||
| } | ||
| self.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be better to preserve the old control flow, but express it using let-else statements. I.e.:
let (Some(self_min), Some(self_max)) = (self.first(), self.last()) else {
// This set is empty, and the empty set is a subset of all sets.
return true;
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that could work too. I'll give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty nice actually! Good catch.
5b3bd95 to
74b52dd
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
74b52dd to
acd0294
Compare
|
@joboet BTW Are there any performance tests for BTree? I could not immediately find them... |
There in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me! I'd be interested in the benchmark results, but don't mind merging this as–is even without them – there aren't really any control-flow changes here.
run-make tests: use edition 2024 Bump run-make tests to edition 2024 to prevent test failures when using 2024 idioms in included code, such as I ran into here: rust-lang#147808.
run-make tests: use edition 2024 Bump run-make tests to edition 2024 to prevent test failures when using 2024 idioms in included code, such as I ran into here: rust-lang#147808.
run-make tests: use edition 2024 Bump run-make tests to edition 2024 to prevent test failures when using 2024 idioms in included code, such as I ran into here: rust-lang#147808.
run-make tests: use edition 2024 Bump run-make tests to edition 2024 to prevent test failures when using 2024 idioms in included code, such as I ran into here: rust-lang#147808.
|
From running benchmarks locally I believe there is no perf impact of these changes. |
|
All right! Then |
Rollup of 12 pull requests Successful merges: - #145768 (Offload device) - #145992 (Stabilize `vec_deque_pop_if`) - #147416 (Early return if span is from expansion so we dont get empty span and ice later on) - #147808 (btree: cleanup difference, intersection, is_subset) - #148520 (style: Use binary literals instead of hex literals in doctests for `highest_one` and `lowest_one`) - #148559 (Add typo suggestion for a misspelt Cargo environment variable) - #148567 (Fix incorrect precedence caused by range expression) - #148570 (Fix mismatched brackets in generated .dir-locals.el) - #148575 (fix dev guide link in rustc_query_system/dep_graph/README.md) - #148578 (core docs: add notes about availability of `Atomic*::from_mut_slice`) - #148603 (Backport 1.91.1 relnotes to main) - #148609 (Sync str::rsplit_once example with str::split_once) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147808 - hkBst:btree-3, r=joboet btree: cleanup difference, intersection, is_subset
No description provided.