Skip to content

Commit

Permalink
Use StringVector instead of Vector{UInt8}
Browse files Browse the repository at this point in the history
This avoids extra allocation and copying for the in-memory string
parsing.
  • Loading branch information
TotalVerb committed Apr 20, 2017
1 parent c97b712 commit 82b4b1e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.4
Compat 0.17.0
Compat 0.24.0
3 changes: 2 additions & 1 deletion src/specialized.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Specialized functions for increased performance when JSON is in-memory
using Compat: StringVector

function parse_string(ps::MemoryParserState)
# "Dry Run": find length of string so we can allocate the right amount of
# memory from the start. Does not do full error checking.
fastpath, len = predict_string(ps)

# Now read the string itself
b = Vector{UInt8}(len)
b = StringVector(len)

# Fast path occurs when the string has no escaped characters. This is quite
# often the case in real-world data, especially when keys are short strings.
Expand Down

0 comments on commit 82b4b1e

Please sign in to comment.