Skip to content

Commit

Permalink
restore special case parsing of numbers for in memory JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Nov 4, 2018
1 parent e8d39a6 commit dd39060
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/Parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ abstract type ParserState end
mutable struct MemoryParserState <: ParserState
utf8::String
s::Int
utf8array::Vector{UInt8}
end

# it is convenient to access MemoryParserState like a Vector{UInt8} to avoid copies
Base.@propagate_inbounds Base.getindex(state::MemoryParserState, i::Int) = codeunit(state.utf8, i)
Base.length(state::MemoryParserState) = sizeof(state.utf8)
Base.unsafe_convert(::Type{Ptr{UInt8}}, state::MemoryParserState) = unsafe_convert(Ptr{UInt8}, state.utf8)
Base.unsafe_convert(::Type{Ptr{UInt8}}, state::MemoryParserState) = Base.unsafe_convert(Ptr{UInt8}, state.utf8)

mutable struct StreamingParserState{T <: IO} <: ParserState
io::T
Expand Down Expand Up @@ -409,7 +408,7 @@ function parse(str::AbstractString;
dicttype=Dict{String,Any},
inttype::Type{<:Real}=Int64)
pc = _get_parsercontext(dicttype, inttype)
ps = MemoryParserState(str, 1, UInt8[])
ps = MemoryParserState(str, 1)
v = parse_value(pc, ps)
chomp_space!(ps)
if hasmore(ps)
Expand Down
4 changes: 2 additions & 2 deletions src/specialized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function parse_string(ps::MemoryParserState, b::IOBuffer)
b
end

function parse_number(ps::MemoryParserState)
function parse_number(pc::ParserContext, ps::MemoryParserState)
s = p = ps.s
e = length(ps)
isint = true
Expand All @@ -140,5 +140,5 @@ function parse_number(ps::MemoryParserState)
end
ps.s = p

number_from_bytes(ps, isint, ps, s, p - 1)
number_from_bytes(pc, ps, isint, ps, s, p - 1)
end

0 comments on commit dd39060

Please sign in to comment.