Skip to content

Commit

Permalink
avoid expensive runtime div in parse (JuliaLang#29892)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored and tkf committed Nov 21, 2018
1 parent a2eb705 commit 22afe9b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
end

base = convert(T, base)
m::T = div(typemax(T) - base + 1, base)
# Special case the common cases of base being 10 or 16 to avoid expensive runtime div
m::T = base == 10 ? div(typemax(T) - T(9), T(10)) :
base == 16 ? div(typemax(T) - T(15), T(16)) :
div(typemax(T) - base + 1, base)
n::T = 0
a::Int = base <= 36 ? 10 : 36
_0 = UInt32('0')
Expand Down

0 comments on commit 22afe9b

Please sign in to comment.