oj 3.11.5 → 3.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/ext/oj/compat.c +32 -27
- data/ext/oj/custom.c +3 -15
- data/ext/oj/dump.c +39 -42
- data/ext/oj/dump_strict.c +1 -1
- data/ext/oj/fast.c +53 -22
- data/ext/oj/hash.c +41 -4
- data/ext/oj/hash.h +2 -0
- data/ext/oj/mimic_json.c +15 -13
- data/ext/oj/object.c +33 -5
- data/ext/oj/oj.c +116 -33
- data/ext/oj/oj.h +3 -1
- data/ext/oj/parse.c +1 -1
- data/ext/oj/parse.h +3 -0
- data/ext/oj/rails.c +2 -1
- data/ext/oj/scp.c +4 -16
- data/ext/oj/strict.c +67 -22
- data/ext/oj/wab.c +35 -18
- data/lib/oj/mimic.rb +2 -0
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +2 -0
- data/pages/Options.md +23 -5
- data/test/foo.rb +2 -44
- data/test/perf.rb +1 -1
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/test_fast.rb +32 -2
- data/test/test_various.rb +2 -0
- metadata +3 -3
data/test/perf.rb
CHANGED
data/test/perf_scp.rb
CHANGED
@@ -14,16 +14,16 @@ require 'oj'
|
|
14
14
|
|
15
15
|
$verbose = false
|
16
16
|
$indent = 0
|
17
|
-
$iter =
|
17
|
+
$iter = 50_000
|
18
18
|
$with_bignum = false
|
19
|
-
$size =
|
19
|
+
$size = 1
|
20
20
|
|
21
21
|
opts = OptionParser.new
|
22
22
|
opts.on("-v", "verbose") { $verbose = true }
|
23
23
|
opts.on("-c", "--count [Int]", Integer, "iterations") { |i| $iter = i }
|
24
24
|
opts.on("-i", "--indent [Int]", Integer, "indentation") { |i| $indent = i }
|
25
|
-
opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)")
|
26
|
-
opts.on("-b", "with bignum")
|
25
|
+
opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)") { |i| $size = i }
|
26
|
+
opts.on("-b", "with bignum") { $with_bignum = true }
|
27
27
|
opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
|
28
28
|
files = opts.parse(ARGV)
|
29
29
|
|
@@ -47,7 +47,7 @@ if 0 < $size
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
Oj.default_options = { :indent => $indent, :mode => :
|
50
|
+
Oj.default_options = { :indent => $indent, :mode => :strict, cache_keys: true, cache_str: 5 }
|
51
51
|
|
52
52
|
$json = Oj.dump($obj)
|
53
53
|
$failed = {} # key is same as String used in tests later
|
@@ -105,7 +105,7 @@ class AllHandler < Oj::ScHandler
|
|
105
105
|
|
106
106
|
def hash_set(h, key, value)
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def array_append(a, value)
|
110
110
|
end
|
111
111
|
|
@@ -137,10 +137,11 @@ end
|
|
137
137
|
puts '-' * 80
|
138
138
|
puts "Parse Performance"
|
139
139
|
perf = Perf.new()
|
140
|
-
perf.add('Oj::Saj', 'all') { Oj.saj_parse(saj_handler, $json) }
|
141
|
-
perf.add('Oj::Saj', 'none') { Oj.saj_parse(no_saj, $json) }
|
142
|
-
perf.add('Oj::Scp', 'all') { Oj.sc_parse(sc_handler, $json) }
|
143
|
-
perf.add('Oj::Scp', 'none') { Oj.sc_parse(no_handler, $json) }
|
140
|
+
perf.add('Oj::Saj.all', 'all') { Oj.saj_parse(saj_handler, $json) }
|
141
|
+
perf.add('Oj::Saj.none', 'none') { Oj.saj_parse(no_saj, $json) }
|
142
|
+
perf.add('Oj::Scp.all', 'all') { Oj.sc_parse(sc_handler, $json) }
|
143
|
+
perf.add('Oj::Scp.none', 'none') { Oj.sc_parse(no_handler, $json) }
|
144
|
+
perf.add('Oj::load', 'none') { Oj.wab_load($json) }
|
144
145
|
perf.add('Yajl', 'parse') { Yajl::Parser.parse($json) } unless $failed.has_key?('Yajl')
|
145
146
|
perf.add('JSON::Ext', 'parse') { JSON::Ext::Parser.new($json).parse } unless $failed.has_key?('JSON::Ext')
|
146
147
|
perf.run($iter)
|
data/test/perf_strict.rb
CHANGED
@@ -15,6 +15,8 @@ $iter = 20000
|
|
15
15
|
$with_bignum = false
|
16
16
|
$with_nums = true
|
17
17
|
$size = 0
|
18
|
+
$symbolize = false
|
19
|
+
$cache_keys = true
|
18
20
|
|
19
21
|
opts = OptionParser.new
|
20
22
|
opts.on("-v", "verbose") { $verbose = true }
|
@@ -23,6 +25,8 @@ opts.on("-i", "--indent [Int]", Integer, "indentation") { |i| $indent = i }
|
|
23
25
|
opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)") { |i| $size = i }
|
24
26
|
opts.on("-b", "with bignum") { $with_bignum = true }
|
25
27
|
opts.on("-n", "without numbers") { $with_nums = false }
|
28
|
+
opts.on("-z", "--symbolize", "symbolize keys") { $symbolize = true }
|
29
|
+
opts.on("-k", "--no-cache", "turn off key caching") { $cache_keys = false }
|
26
30
|
opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
|
27
31
|
files = opts.parse(ARGV)
|
28
32
|
|
@@ -51,7 +55,7 @@ else
|
|
51
55
|
}
|
52
56
|
end
|
53
57
|
|
54
|
-
Oj.default_options = { :indent => $indent, :mode => :strict }
|
58
|
+
Oj.default_options = { :indent => $indent, :mode => :strict, cache_keys: $cache_keys, cache_str: 5 }
|
55
59
|
|
56
60
|
if 0 < $size
|
57
61
|
o = $obj
|
@@ -62,9 +66,6 @@ if 0 < $size
|
|
62
66
|
end
|
63
67
|
|
64
68
|
$json = Oj.dump($obj)
|
65
|
-
$obj_json = Oj.dump($obj, :mode => :object)
|
66
|
-
#puts "*** size: #{$obj_json.size}"
|
67
|
-
#puts "*** #{$obj_json}"
|
68
69
|
$failed = {} # key is same as String used in tests later
|
69
70
|
|
70
71
|
def capture_error(tag, orig, load_key, dump_key, &blk)
|
@@ -77,8 +78,13 @@ def capture_error(tag, orig, load_key, dump_key, &blk)
|
|
77
78
|
end
|
78
79
|
|
79
80
|
# Verify that all packages dump and load correctly and return the same Object as the original.
|
80
|
-
capture_error('Oj:strict', $obj, 'load', 'dump') { |o|
|
81
|
-
|
81
|
+
capture_error('Oj:strict', $obj, 'load', 'dump') { |o|
|
82
|
+
Oj.strict_load(Oj.dump(o))
|
83
|
+
}
|
84
|
+
capture_error('Yajl', $obj, 'encode', 'parse') { |o|
|
85
|
+
require 'yajl'
|
86
|
+
Yajl::Parser.parse(Yajl::Encoder.encode(o))
|
87
|
+
}
|
82
88
|
capture_error('JSON::Ext', $obj, 'generate', 'parse') { |o|
|
83
89
|
require 'json'
|
84
90
|
require 'json/ext'
|
@@ -86,16 +92,11 @@ capture_error('JSON::Ext', $obj, 'generate', 'parse') { |o|
|
|
86
92
|
JSON.parser = JSON::Ext::Parser
|
87
93
|
JSON.parse(JSON.generate(o))
|
88
94
|
}
|
89
|
-
|
90
|
-
|
91
|
-
JSON.generator = JSON::Pure::Generator
|
92
|
-
JSON.parser = JSON::Pure::Parser
|
93
|
-
JSON.parse(JSON.generate(o))
|
94
|
-
}
|
95
|
+
|
96
|
+
Oj.default_options = { symbol_keys: $symbolize }
|
95
97
|
|
96
98
|
if $verbose
|
97
99
|
puts "json:\n#{$json}\n"
|
98
|
-
puts "object json:\n#{$obj_json}\n"
|
99
100
|
puts "Oj loaded object:\n#{Oj.strict_load($json)}\n"
|
100
101
|
puts "Yajl loaded object:\n#{Yajl::Parser.parse($json)}\n"
|
101
102
|
puts "JSON loaded object:\n#{JSON::Ext::Parser.new($json).parse}\n"
|
@@ -105,15 +106,12 @@ puts '-' * 80
|
|
105
106
|
puts "Strict Parse Performance"
|
106
107
|
perf = Perf.new()
|
107
108
|
unless $failed.has_key?('JSON::Ext')
|
108
|
-
perf.add('JSON::Ext', 'parse') { JSON.parse($json) }
|
109
|
+
perf.add('JSON::Ext', 'parse') { JSON.parse($json, symbolize_names: $symbolize) }
|
109
110
|
perf.before('JSON::Ext') { JSON.parser = JSON::Ext::Parser }
|
110
111
|
end
|
111
|
-
unless $failed.has_key?('JSON::Pure')
|
112
|
-
perf.add('JSON::Pure', 'parse') { JSON.parse($json) }
|
113
|
-
perf.before('JSON::Pure') { JSON.parser = JSON::Pure::Parser }
|
114
|
-
end
|
115
112
|
unless $failed.has_key?('Oj:strict')
|
116
113
|
perf.add('Oj:strict', 'strict_load') { Oj.strict_load($json) }
|
114
|
+
perf.add('Oj:wab', 'wab_load') { Oj.wab_load($json) }
|
117
115
|
end
|
118
116
|
perf.add('Yajl', 'parse') { Yajl::Parser.parse($json) } unless $failed.has_key?('Yajl')
|
119
117
|
perf.run($iter)
|
@@ -125,12 +123,8 @@ unless $failed.has_key?('JSON::Ext')
|
|
125
123
|
perf.add('JSON::Ext', 'dump') { JSON.generate($obj) }
|
126
124
|
perf.before('JSON::Ext') { JSON.generator = JSON::Ext::Generator }
|
127
125
|
end
|
128
|
-
unless $failed.has_key?('JSON::Pure')
|
129
|
-
perf.add('JSON::Pure', 'generate') { JSON.generate($obj) }
|
130
|
-
perf.before('JSON::Pure') { JSON.generator = JSON::Pure::Generator }
|
131
|
-
end
|
132
126
|
unless $failed.has_key?('Oj:strict')
|
133
|
-
perf.add('Oj:strict', 'dump') { Oj.dump($obj
|
127
|
+
perf.add('Oj:strict', 'dump') { Oj.dump($obj) }
|
134
128
|
end
|
135
129
|
perf.add('Yajl', 'encode') { Yajl::Encoder.encode($obj) } unless $failed.has_key?('Yajl')
|
136
130
|
perf.run($iter)
|
data/test/test_fast.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding:
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
$: << File.dirname(__FILE__)
|
5
5
|
|
@@ -279,10 +279,26 @@ class DocTest < Minitest::Test
|
|
279
279
|
['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
280
280
|
['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
281
281
|
['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
|
282
|
+
['/nothing', nil],
|
283
|
+
['/array/10', nil],
|
282
284
|
].each do |path,val|
|
283
|
-
|
285
|
+
if val.nil?
|
286
|
+
assert_nil(doc.fetch(path))
|
287
|
+
else
|
288
|
+
assert_equal(val, doc.fetch(path))
|
289
|
+
end
|
284
290
|
end
|
285
291
|
end
|
292
|
+
# verify empty hash and arrays return nil when a member is requested
|
293
|
+
Oj::Doc.open('{}') do |doc|
|
294
|
+
assert_nil(doc.fetch('/x'))
|
295
|
+
assert_nil(doc.fetch('/0'))
|
296
|
+
end
|
297
|
+
Oj::Doc.open('[]') do |doc|
|
298
|
+
assert_nil(doc.fetch('/x'))
|
299
|
+
assert_nil(doc.fetch('/0'))
|
300
|
+
end
|
301
|
+
|
286
302
|
end
|
287
303
|
|
288
304
|
def test_move_fetch_path
|
@@ -297,6 +313,20 @@ class DocTest < Minitest::Test
|
|
297
313
|
end
|
298
314
|
end
|
299
315
|
|
316
|
+
def test_exisits
|
317
|
+
Oj::Doc.open(@json1) do |doc|
|
318
|
+
[['/array/1', true],
|
319
|
+
['/array/1', true],
|
320
|
+
['/array/1/hash', true],
|
321
|
+
['/array/1/dash', false],
|
322
|
+
['/array/3', false],
|
323
|
+
['/nothing', false],
|
324
|
+
].each do |path,val|
|
325
|
+
assert_equal(val, doc.exists?(path))
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
300
330
|
def test_home
|
301
331
|
Oj::Doc.open(@json1) do |doc|
|
302
332
|
doc.move('/array/1/num')
|
data/test/test_various.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
285
|
- !ruby/object:Gem::Version
|
286
286
|
version: '0'
|
287
287
|
requirements: []
|
288
|
-
rubygems_version: 3.2.
|
288
|
+
rubygems_version: 3.2.22
|
289
289
|
signing_key:
|
290
290
|
specification_version: 4
|
291
291
|
summary: A fast JSON parser and serializer.
|