Skip to content

Commit

Permalink
improve performance of parse (#28787)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 22, 2018
1 parent 81b04cf commit 81850b6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions base/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
return nothing
end

base = convert(T,base)
m::T = div(typemax(T)-base+1,base)
base = convert(T, base)
m::T = div(typemax(T) - base + 1, base)
n::T = 0
a::Int = base <= 36 ? 10 : 36
_0 = UInt32('0')
_9 = UInt32('9')
_A = UInt32('A')
_a = UInt32('a')
_Z = UInt32('Z')
_z = UInt32('z')
while n <= m
d::T = '0' <= c <= '9' ? c-'0' :
'A' <= c <= 'Z' ? c-'A'+10 :
'a' <= c <= 'z' ? c-'a'+a : base
_c = UInt32(c)
d::T = _0 <= _c <= _9 ? _c-_0 :
_A <= _c <= _Z ? _c-_A+ UInt32(10) :
_a <= _c <= _z ? _c-_a+a : base
if d >= base
raise && throw(ArgumentError("invalid base $base digit $(repr(c)) in $(repr(SubString(s,startpos,endpos)))"))
return nothing
Expand All @@ -129,9 +136,10 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
end
(T <: Signed) && (n *= sgn)
while !isspace(c)
d::T = '0' <= c <= '9' ? c-'0' :
'A' <= c <= 'Z' ? c-'A'+10 :
'a' <= c <= 'z' ? c-'a'+a : base
_c = UInt32(c)
d::T = _0 <= _c <= _9 ? _c-_0 :
_A <= _c <= _Z ? _c-_A+ UInt32(10) :
_a <= _c <= _z ? _c-_a+a : base
if d >= base
raise && throw(ArgumentError("invalid base $base digit $(repr(c)) in $(repr(SubString(s,startpos,endpos)))"))
return nothing
Expand Down

0 comments on commit 81850b6

Please sign in to comment.