-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Improve char to int parsing, and add tryparse
method
#59603
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
base: master
Are you sure you want to change the base?
Conversation
Benchmark: ``` julia> s = [rand('0':'9') for i in 1:100000]; julia> function foo(s) n = 0 for i in s n += parse(Int, i) end n end ``` Before: 196 us After: 39 us
Oi, you've sniped me! (just kidding, improvement is nice to see) |
tryparse
method
Test failures are unrelated |
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 PR introduces a lot of unrelated and unmotivated style chagnes that make this function out of like with they style of the surrounding code. Other than that, this seems pretty reasonable.
|
@noinline function _invalid_base(base) | ||
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base")) | ||
end | ||
|
||
@noinline _invalid_digit(base, char) = throw(ArgumentError("invalid base $base digit $(repr(char))")) |
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.
These are weirdly inconsistent?
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.
One is longer than the other, and therefore the line needs to be broken up.
This was orignially a larger PR, but I've shelved the larger refactoring for now.
This PR does two things:
tryparse(::Type{T}, c::AbstractChar; base::Integer=10) where {T <: Integer}
which was previously missing