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.
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
Fix
length(::AbstractUnitRange)
and speed uplength(::AbstractUnitRange{<:Rational})
#41479Fix
length(::AbstractUnitRange)
and speed uplength(::AbstractUnitRange{<:Rational})
#41479Changes from 4 commits
6fd2576
206f154
c8e04d6
4a49d28
6a4a9a8
0078f1e
7110222
926029d
c39e26b
875a0fa
e6528e1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 method not only adds performance but changes behavior as well: Without this method,
length(::AbstractUnitRange{<:Rational})
usesRational
arithmetic, which is checked. The specialized method uses integer arithmetic, so it can overflow.I realize that we are okay with an overflowing
length
, but should this also apply toRational
s, which are using checked arithmetic by default? Or should the behavior be changed so that it matchesRational
arithmetic?I will add a specialized
checked_length(::AbstractUnitRange{<:Rational})
method in any case.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 is okay, since it should generally only overflow for extreme values that are unlikely
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 change would reduce the risk of overflow, but would be slightly less performant (two integer divisions instead of one). Is it worth it?