-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Specialize count for range iterators #112229
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? @scottmcm (rustbot has picked a reviewer for you, use r? to override) |
b423056
to
23b8562
Compare
Since this is an observable change, I'm going to flip it over to For example, today pub fn range_count_demo() -> usize { (0..u128::MAX).count() } just returns ; playground::range_count_demo
; Function Attrs: mustprogress nofree norecurse nosync nounwind nonlazybind willreturn memory(none) uwtable
define noundef i64 @_ZN10playground16range_count_demo17h49ff333a76b29162E() unnamed_addr #0 personality ptr @rust_eh_personality {
start:
ret i64 -1
} |
Hmm, it should be someone on the review rotation, so let's say |
It looks like this change is explicitly allowed by the docs in
So this seems fine to me. @rfcbot fcp merge |
I should have included this in the description too, but I was also taking this into consideration when deciding to implement this. The main justification for not using the default overflow behaviour (hence making observable changes) is because to do so would require augmenting the |
Trying again... @rfcbot fcp merge |
You may also need to flip the label to libs-api |
@BurntSushi just to move this thing - want to retry your fcp? |
@rfcbot fcp merge |
Team member @BurntSushi has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Third time's the charm :) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Gentle nudge to @m-ou-se to merge when you have the chance, since the FCP has ended. |
23b8562
to
08aa6c9
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4514fb9): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 633.405s -> 632.183s (-0.19%) |
Since
size_hint
is already specialized, it feels apt to specializecount
as well. Without any specialized version ofExactSizeIterator::len
orStep::steps_between
, this feels like a more reliable way of accessing this without having to rely on knowing thatsize_hint
is correct.In my case, this is particularly useful to access the
steps_between
implementation forchar
from the standard library without having to compute it manually.I didn't think it was worth modifying the
Step
trait to add a version ofsteps_between
that used native overflow checks since this is just doing one subtraction in most cases anyway, and so I decided to make the inclusive version usechecked_add
so it didn't have this lopsided overflow-checks-but-only-sometimes logic.