oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/perf_wab.rb
CHANGED
@@ -1,131 +1,129 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
$LOAD_PATH << '.'
|
5
|
+
$LOAD_PATH << File.join(__dir__, '../lib')
|
6
|
+
$LOAD_PATH << File.join(__dir__, '../ext')
|
7
7
|
|
8
8
|
require 'optparse'
|
9
9
|
require 'perf'
|
10
10
|
require 'oj'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
@verbose = false
|
13
|
+
@indent = 0
|
14
|
+
@iter = 20_000
|
15
|
+
@with_bignum = false
|
16
|
+
@with_nums = true
|
17
|
+
@size = 0
|
18
18
|
|
19
19
|
opts = OptionParser.new
|
20
|
-
opts.on(
|
21
|
-
opts.on(
|
22
|
-
opts.on(
|
23
|
-
opts.on(
|
24
|
-
opts.on(
|
25
|
-
opts.on(
|
26
|
-
|
20
|
+
opts.on('-v', 'verbose') { @verbose = true }
|
21
|
+
opts.on('-c', '--count [Int]', Integer, 'iterations') { |i| @iter = i }
|
22
|
+
opts.on('-i', '--indent [Int]', Integer, 'indentation') { |i| @indent = i }
|
23
|
+
opts.on('-s', '--size [Int]', Integer, 'size (~Kbytes)') { |i| @size = i }
|
24
|
+
opts.on('-b', 'with bignum') { @with_bignum = true }
|
25
|
+
opts.on('-h', '--help', 'Show this display') { puts opts; Process.exit!(0) }
|
26
|
+
opts.parse(ARGV)
|
27
27
|
|
28
|
-
|
28
|
+
@obj = {
|
29
29
|
a: 'Alpha', # string
|
30
30
|
b: true, # boolean
|
31
|
-
c:
|
32
|
-
d: [ true, [false, [-
|
31
|
+
c: 12_345, # number
|
32
|
+
d: [ true, [false, [-123_456_789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
|
33
33
|
e: { zero: nil, one: 1, two: 2, three: [3], four: [0, 1, 2, 3, 4] }, # hash
|
34
34
|
f: nil, # nil
|
35
35
|
h: { a: { b: { c: { d: {e: { f: { g: nil }}}}}}}, # deep hash, not that deep
|
36
36
|
i: [[[[[[[nil]]]]]]] # deep array, again, not that deep
|
37
37
|
}
|
38
|
-
|
38
|
+
@obj[:g] = 12_345_678_901_234_567_890_123_456_789 if @with_bignum
|
39
39
|
|
40
|
-
Oj.default_options = { :indent =>
|
40
|
+
Oj.default_options = { :indent => @indent, :mode => :wab }
|
41
41
|
|
42
|
-
if 0 <
|
43
|
-
|
44
|
-
|
45
|
-
(4 *
|
46
|
-
|
42
|
+
if 0 < @size
|
43
|
+
ob = @obj
|
44
|
+
@obj = []
|
45
|
+
(4 * @size).times do
|
46
|
+
@obj << ob
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
#puts "*** size: #{
|
53
|
-
#puts "*** #{
|
54
|
-
|
50
|
+
@json = Oj.dump(@obj)
|
51
|
+
@obj_json = Oj.dump(@obj, :mode => :object)
|
52
|
+
# puts "*** size: #{@obj_json.size}"
|
53
|
+
# puts "*** #{@obj_json}"
|
54
|
+
@failed = {} # key is same as String used in tests later
|
55
55
|
|
56
56
|
def capture_error(tag, orig, load_key, dump_key, &blk)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
$failed[tag] = "#{e.class}: #{e.message}"
|
62
|
-
end
|
57
|
+
obj = blk.call(orig)
|
58
|
+
raise "#{tag} #{dump_key} and #{load_key} did not return the same object as the original." unless orig == obj
|
59
|
+
rescue Exception => e
|
60
|
+
@failed[tag] = "#{e.class}: #{e.message}"
|
63
61
|
end
|
64
62
|
|
65
63
|
# Verify that all packages dump and load correctly and return the same Object as the original.
|
66
|
-
capture_error('Oj:wab',
|
67
|
-
capture_error('Yajl',
|
68
|
-
capture_error('JSON::Ext',
|
64
|
+
capture_error('Oj:wab', @obj, 'load', 'dump') { |o| Oj.wab_load(Oj.dump(o, :mode => :wab)) }
|
65
|
+
capture_error('Yajl', @obj, 'encode', 'parse') { |o| require 'yajl'; Yajl::Parser.parse(Yajl::Encoder.encode(o)) }
|
66
|
+
capture_error('JSON::Ext', @obj, 'generate', 'parse') { |o|
|
69
67
|
require 'json'
|
70
68
|
require 'json/ext'
|
71
69
|
JSON.generator = JSON::Ext::Generator
|
72
70
|
JSON.parser = JSON::Ext::Parser
|
73
71
|
JSON.parse(JSON.generate(o))
|
74
72
|
}
|
75
|
-
capture_error('JSON::Pure',
|
73
|
+
capture_error('JSON::Pure', @obj, 'generate', 'parse') { |o|
|
76
74
|
require 'json/pure'
|
77
75
|
JSON.generator = JSON::Pure::Generator
|
78
76
|
JSON.parser = JSON::Pure::Parser
|
79
77
|
JSON.parse(JSON.generate(o))
|
80
78
|
}
|
81
79
|
|
82
|
-
if
|
83
|
-
puts "json:\n#{
|
84
|
-
puts "object json:\n#{
|
85
|
-
puts "Oj loaded object:\n#{Oj.wab_load(
|
86
|
-
puts "Yajl loaded object:\n#{Yajl::Parser.parse(
|
87
|
-
puts "JSON loaded object:\n#{JSON::Ext::Parser.new(
|
80
|
+
if @verbose
|
81
|
+
puts "json:\n#{@json}\n"
|
82
|
+
puts "object json:\n#{@obj_json}\n"
|
83
|
+
puts "Oj loaded object:\n#{Oj.wab_load(@json)}\n"
|
84
|
+
puts "Yajl loaded object:\n#{Yajl::Parser.parse(@json)}\n"
|
85
|
+
puts "JSON loaded object:\n#{JSON::Ext::Parser.new(@json).parse}\n"
|
88
86
|
end
|
89
87
|
|
90
88
|
puts '-' * 80
|
91
|
-
puts
|
89
|
+
puts 'Wab Parse Performance'
|
92
90
|
perf = Perf.new()
|
93
|
-
unless
|
94
|
-
perf.add('JSON::Ext', 'parse') { JSON.parse(
|
91
|
+
unless @failed.key?('JSON::Ext')
|
92
|
+
perf.add('JSON::Ext', 'parse') { JSON.parse(@json) }
|
95
93
|
perf.before('JSON::Ext') { JSON.parser = JSON::Ext::Parser }
|
96
94
|
end
|
97
|
-
unless
|
98
|
-
perf.add('JSON::Pure', 'parse') { JSON.parse(
|
95
|
+
unless @failed.key?('JSON::Pure')
|
96
|
+
perf.add('JSON::Pure', 'parse') { JSON.parse(@json) }
|
99
97
|
perf.before('JSON::Pure') { JSON.parser = JSON::Pure::Parser }
|
100
98
|
end
|
101
|
-
unless
|
102
|
-
perf.add('Oj:wab', 'wab_load') { Oj.wab_load(
|
99
|
+
unless @failed.key?('Oj:wab')
|
100
|
+
perf.add('Oj:wab', 'wab_load') { Oj.wab_load(@json) }
|
103
101
|
end
|
104
|
-
perf.add('Yajl', 'parse') { Yajl::Parser.parse(
|
105
|
-
perf.run(
|
102
|
+
perf.add('Yajl', 'parse') { Yajl::Parser.parse(@json) } unless @failed.key?('Yajl')
|
103
|
+
perf.run(@iter)
|
106
104
|
|
107
105
|
puts '-' * 80
|
108
|
-
puts
|
106
|
+
puts 'Wab Dump Performance'
|
109
107
|
perf = Perf.new()
|
110
|
-
unless
|
111
|
-
perf.add('JSON::Ext', 'dump') { JSON.generate(
|
108
|
+
unless @failed.key?('JSON::Ext')
|
109
|
+
perf.add('JSON::Ext', 'dump') { JSON.generate(@obj) }
|
112
110
|
perf.before('JSON::Ext') { JSON.generator = JSON::Ext::Generator }
|
113
111
|
end
|
114
|
-
unless
|
115
|
-
perf.add('JSON::Pure', 'generate') { JSON.generate(
|
112
|
+
unless @failed.key?('JSON::Pure')
|
113
|
+
perf.add('JSON::Pure', 'generate') { JSON.generate(@obj) }
|
116
114
|
perf.before('JSON::Pure') { JSON.generator = JSON::Pure::Generator }
|
117
115
|
end
|
118
|
-
unless
|
119
|
-
perf.add('Oj:wab', 'dump') { Oj.dump(
|
116
|
+
unless @failed.key?('Oj:wab')
|
117
|
+
perf.add('Oj:wab', 'dump') { Oj.dump(@obj, :mode => :wab) }
|
120
118
|
end
|
121
|
-
perf.add('Yajl', 'encode') { Yajl::Encoder.encode(
|
122
|
-
perf.run(
|
119
|
+
perf.add('Yajl', 'encode') { Yajl::Encoder.encode(@obj) } unless @failed.key?('Yajl')
|
120
|
+
perf.run(@iter)
|
123
121
|
|
124
122
|
puts
|
125
123
|
puts '-' * 80
|
126
124
|
puts
|
127
125
|
|
128
|
-
unless
|
129
|
-
puts
|
130
|
-
|
126
|
+
unless @failed.empty?
|
127
|
+
puts 'The following packages were not included for the reason listed'
|
128
|
+
@failed.each { |tag, msg| puts "***** #{tag}: #{msg}" }
|
131
129
|
end
|
data/test/prec.rb
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'oj'
|
4
4
|
|
5
|
-
extras = {
|
5
|
+
extras = { 'locationLng' => -97.14690769100295 }
|
6
6
|
|
7
|
-
Oj.default_options = {float_precision: 17}
|
7
|
+
Oj.default_options = { float_precision: 17 }
|
8
8
|
|
9
9
|
encoded = Oj.dump(extras)
|
10
10
|
puts encoded
|
11
11
|
puts Oj.load(encoded)
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'active_record'
|
14
14
|
|
15
15
|
Oj::Rails.set_encoder()
|
16
16
|
Oj::Rails.set_decoder()
|
17
17
|
|
18
|
-
Oj.default_options = {float_precision: 17}
|
19
|
-
# Using Oj rails encoder, gets the correct value: {
|
18
|
+
Oj.default_options = { float_precision: 17 }
|
19
|
+
# Using Oj rails encoder, gets the correct value: { 'locationLng':-97.14690769100295 }
|
20
20
|
encoded = ActiveSupport::JSON.encode(extras)
|
21
21
|
puts encoded
|
22
22
|
puts ActiveSupport::JSON.decode(encoded)
|
data/test/sample/change.rb
CHANGED
data/test/sample/dir.rb
CHANGED
data/test/sample/doc.rb
CHANGED
data/test/sample/file.rb
CHANGED
data/test/sample/group.rb
CHANGED
data/test/sample/hasprops.rb
CHANGED
data/test/sample/layer.rb
CHANGED
data/test/sample/rect.rb
CHANGED
data/test/sample/shape.rb
CHANGED
data/test/sample/text.rb
CHANGED
data/test/sample.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby -wW2
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
if $
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
if $PROGRAM_NAME == __FILE__
|
5
|
+
$LOAD_PATH << '.'
|
6
|
+
$LOAD_PATH << '..'
|
7
|
+
$LOAD_PATH << '../lib'
|
8
|
+
$LOAD_PATH << '../ext'
|
8
9
|
end
|
9
10
|
|
10
|
-
require 'pp'
|
11
11
|
require 'sample/doc'
|
12
12
|
|
13
13
|
def sample_doc(size=3)
|
14
14
|
colors = [ :black, :gray, :white, :red, :blue, :yellow, :green, :purple, :orange ]
|
15
15
|
|
16
|
-
d =
|
16
|
+
d = Sample::Doc.new('Sample')
|
17
17
|
|
18
18
|
# add some history
|
19
19
|
(0..size * 10).each do |i|
|
@@ -22,22 +22,22 @@ def sample_doc(size=3)
|
|
22
22
|
|
23
23
|
# add some layers
|
24
24
|
(1..size).each do |i|
|
25
|
-
layer =
|
25
|
+
layer = Sample::Layer.new("Layer-#{i}")
|
26
26
|
(1..size).each do |j|
|
27
|
-
g =
|
27
|
+
g = Sample::Group.new
|
28
28
|
(1..size).each do |k|
|
29
|
-
g2 =
|
30
|
-
r =
|
31
|
-
|
29
|
+
g2 = Sample::Group.new
|
30
|
+
r = Sample::Rect.new((j * 40) + 10.0, i * 10.0,
|
31
|
+
10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
|
32
32
|
r.add_prop(:part_of, layer.name)
|
33
33
|
g2 << r
|
34
|
-
g2 <<
|
34
|
+
g2 << Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
|
35
35
|
g << g2
|
36
36
|
end
|
37
|
-
g2 =
|
37
|
+
g2 = Sample::Group.new
|
38
38
|
(1..size).each do |k|
|
39
|
-
o =
|
40
|
-
|
39
|
+
o = Sample::Oval.new((j * 40) + 12.0, (i * 10.0) + 2.0,
|
40
|
+
6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
|
41
41
|
o.add_prop(:inside, true)
|
42
42
|
g << o
|
43
43
|
end
|
data/test/sample_json.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
if $
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
if $PROGRAM_NAME == __FILE__
|
5
|
+
$LOAD_PATH << '.'
|
6
|
+
$LOAD_PATH << '..'
|
7
|
+
$LOAD_PATH << '../lib'
|
8
|
+
$LOAD_PATH << '../ext'
|
8
9
|
end
|
9
10
|
|
10
|
-
require 'pp'
|
11
11
|
require 'oj'
|
12
12
|
|
13
13
|
def sample_json(size=3)
|
@@ -32,6 +32,6 @@ def sample_json(size=3)
|
|
32
32
|
container
|
33
33
|
end
|
34
34
|
|
35
|
-
if $
|
36
|
-
File.
|
35
|
+
if $PROGRAM_NAME == __FILE__
|
36
|
+
File.write('sample.json', Oj.dump(sample_json(3), :indent => 2))
|
37
37
|
end
|