Skip to content

Commit

Permalink
Refactor JSON::Ext::Parser to split configuration and parsing state
Browse files Browse the repository at this point in the history
Ref: #718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

Co-Authored-By: Étienne Barrié <[email protected]>
  • Loading branch information
byroot and etiennebarrie committed Jan 13, 2025
1 parent 8c352e3 commit c8d5236
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 845 deletions.
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ EXT_GENERATOR_DL = "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}"
EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c"

JAVA_DIR = "java/src/json/ext"
JAVA_RAGEL_PATH = "#{JAVA_DIR}/Parser.rl"
JAVA_PARSER_SRC = "#{JAVA_DIR}/Parser.java"
JAVA_RAGEL_PATH = "#{JAVA_DIR}/ParserConfig.rl"
JAVA_PARSER_SRC = "#{JAVA_DIR}/ParserConfig.java"
JAVA_SOURCES = FileList["#{JAVA_DIR}/*.java"]
JAVA_CLASSES = []
JRUBY_PARSER_JAR = File.expand_path("lib/json/ext/parser.jar")
Expand Down Expand Up @@ -95,9 +95,9 @@ end
file JAVA_PARSER_SRC => JAVA_RAGEL_PATH do
cd JAVA_DIR do
if RAGEL_CODEGEN == 'ragel'
sh "ragel Parser.rl -J -o Parser.java"
sh "ragel ParserConfig.rl -J -o ParserConfig.java"
else
sh "ragel -x Parser.rl | #{RAGEL_CODEGEN} -J"
sh "ragel -x ParserConfig.rl | #{RAGEL_CODEGEN} -J"
end
end
end
Expand Down
Loading

0 comments on commit c8d5236

Please sign in to comment.