Perhaps I am doing something not the right way, but if in v0.6.0
I define
function tryparse_digits(str, start, stop)
n = 0
pos = start
@inbounds while pos ≤ stop
chr, next_pos = next(str, pos)
if '0' ≤ chr ≤ '9'
n = n*10 + (chr - '0')
pos = next_pos
else
return Nullable{Int}()
end
end
Nullable(n)
end
then
julia> @code_warntype tryparse_digits("1980", 1, 4)
Variables:
#self#::#tryparse_digits
str::String
start::Int64
stop::Int64
chr::Char
next_pos::Int64
#temp#@_7::Int64
n::Int64
pos::Int64
#temp#@_10::Bool
p::Ptr{UInt8}
b::UInt8
#temp#@_13::Tuple{Char,Int64}
Body:
begin
n::Int64 = 0 # line 3:
pos::Int64 = start::Int64 # line 4:
$(Expr(:inbounds, true))
NewvarNode(:(chr::Char))
NewvarNode(:(next_pos::Int64))
8:
unless (Base.sle_int)(pos::Int64, stop::Int64)::Bool goto 65 # line 5:
$(Expr(:inbounds, false))
# meta: location strings/string.jl next 196
NewvarNode(:(p::Ptr{UInt8}))
NewvarNode(:(b::UInt8)) # line 197:
16: # line 199:
$(Expr(:inbounds, false))
# meta: location strings/string.jl pointer 51
# meta: location pointer.jl unsafe_convert 37
SSAValue(4) = $(Expr(:foreigncall, :(:jl_value_ptr), Ptr{Void}, svec(Any), :(
str), 0))
SSAValue(3) = (Core.sizeof)(Base.Int)::Int64
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
p::Ptr{UInt8} = (Base.bitcast)(Ptr{UInt8}, (Base.bitcast)(Ptr{Void}, (Base.ad
d_int)((Base.bitcast)(UInt64, SSAValue(4)), (Base.bitcast)(UInt64, SSAValue(3)))::U
Int64)) # line 200:
b::UInt8 = (Base.pointerref)(p::Ptr{UInt8}, pos::Int64, 1)::UInt8 # line 201:
unless (Base.ult_int)(b::UInt8, 0x80)::Bool goto 34 # line 202:
#temp#@_13::Tuple{Char,Int64} = (Core.tuple)((Base.bitcast)(Char, (Base.zext_
int)(UInt32, b::UInt8)::UInt32), (Base.add_int)(pos::Int64, 1)::Int64)::Tuple{Char,
Int64}
goto 37
34: # line 204:
#temp#@_13::Tuple{Char,Int64} = $(Expr(:invoke, MethodInstance for slow_utf8_
next(::Ptr{UInt8}, ::UInt8, ::Int64, ::Int64), :(Base.slow_utf8_next), :(p), :(b),
:(pos), :((Core.getfield)(str, :len)::Int64)))
37:
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(0) = #temp#@_13::Tuple{Char,Int64}
SSAValue(5) = (Base.getfield)(SSAValue(0), 1)::Char
SSAValue(6) = (Base.add_int)(1, 1)::Int64
chr::Char = SSAValue(5)
SSAValue(7) = (Base.getfield)(SSAValue(0), 2)::Int64
SSAValue(8) = (Base.add_int)(2, 1)::Int64
next_pos::Int64 = SSAValue(7) # line 6:
unless (Base.not_int)((Base.ult_int)((Base.bitcast)(UInt32, chr::Char), (Base
.bitcast)(UInt32, '0'))::Bool)::Bool goto 51
#temp#@_10::Bool = (Base.not_int)((Base.ult_int)((Base.bitcast)(UInt32, '9'),
(Base.bitcast)(UInt32, chr::Char))::Bool)::Bool
goto 53
51:
#temp#@_10::Bool = false
53:
unless #temp#@_10::Bool goto 60 # line 7:
n::Int64 = (Base.add_int)((Base.mul_int)(n::Int64, 10)::Int64, (Base.sub_int)
((Base.zext_int)(Int64, (Base.bitcast)(UInt32, chr::Char))::Int64, (Base.zext_int)(
Int64, (Base.bitcast)(UInt32, '0'))::Int64)::Int64)::Int64 # line 8:
pos::Int64 = next_pos::Int64
goto 63
60: # line 10:
return $(Expr(:new, Nullable{Int64}, false))
63:
goto 8
65:
$(Expr(:inbounds, :pop)) # line 13:
return $(Expr(:new, Nullable{Int64}, true, :(n)))
end::Nullable{Int64}