Skip to content

Commit 05eb9af

Browse files
etiennebarriebyroot
andcommitted
JSON::Coder#load
Co-authored-by: Jean Boussier <[email protected]>
1 parent d35fe1e commit 05eb9af

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

benchmark/parser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
def benchmark_parsing(name, json_output)
1717
puts "== Parsing #{name} (#{json_output.size} bytes)"
18+
coder = JSON::Coder.new
1819

1920
Benchmark.ips do |x|
2021
x.report("json") { JSON.parse(json_output) } if RUN[:json]
22+
x.report("json_coder") { coder.load(json_output) } if RUN[:json_coder]
2123
x.report("oj") { Oj.load(json_output) } if RUN[:oj]
2224
x.report("Oj::Parser") { Oj::Parser.new(:usual).parse(json_output) } if RUN[:oj]
2325
x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]

lib/json/common.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,16 @@ def initialize(options = nil, &as_json)
848848
end
849849
options[:as_json] = as_json if as_json
850850
@state = State.new(options)
851+
@parser_config = Ext::Parser::Config.new(options)
851852
end
852853

853854
def dump(...)
854855
@state.generate(...)
855856
end
857+
858+
def load(source)
859+
@parser_config.parse(source)
860+
end
856861
end
857862
end
858863

0 commit comments

Comments
 (0)