oj 3.9.1 → 3.16.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1452 -0
- data/README.md +21 -6
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +50 -68
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +60 -62
- data/ext/oj/cache8.h +9 -36
- data/ext/oj/circarray.c +38 -42
- data/ext/oj/circarray.h +12 -13
- data/ext/oj/code.c +158 -179
- data/ext/oj/code.h +20 -22
- data/ext/oj/compat.c +145 -205
- data/ext/oj/custom.c +740 -880
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +1145 -844
- data/ext/oj/dump.h +71 -57
- data/ext/oj/dump_compat.c +575 -655
- data/ext/oj/dump_leaf.c +96 -186
- data/ext/oj/dump_object.c +533 -660
- data/ext/oj/dump_strict.c +306 -340
- data/ext/oj/encode.h +4 -33
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +28 -28
- data/ext/oj/err.h +39 -42
- data/ext/oj/extconf.rb +28 -7
- data/ext/oj/fast.c +1052 -1113
- 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 +471 -430
- data/ext/oj/object.c +532 -580
- data/ext/oj/odd.c +156 -142
- data/ext/oj/odd.h +25 -26
- data/ext/oj/oj.c +1346 -961
- data/ext/oj/oj.h +307 -290
- data/ext/oj/parse.c +954 -858
- data/ext/oj/parse.h +74 -72
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +103 -0
- data/ext/oj/rails.c +819 -836
- data/ext/oj/rails.h +8 -11
- data/ext/oj/reader.c +136 -147
- data/ext/oj/reader.h +69 -83
- data/ext/oj/resolve.c +41 -63
- data/ext/oj/resolve.h +4 -6
- data/ext/oj/rxclass.c +69 -72
- data/ext/oj/rxclass.h +12 -13
- data/ext/oj/saj.c +440 -485
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +79 -118
- data/ext/oj/simd.h +10 -0
- data/ext/oj/sparse.c +739 -709
- data/ext/oj/stream_writer.c +141 -175
- data/ext/oj/strict.c +103 -128
- data/ext/oj/string_writer.c +244 -261
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +42 -15
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.c +107 -107
- data/ext/oj/util.h +4 -3
- data/ext/oj/val_stack.c +61 -78
- data/ext/oj/val_stack.h +80 -114
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +316 -361
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +8 -1
- data/lib/oj/easy_hash.rb +9 -9
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +54 -20
- 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 -8
- data/pages/Compatibility.md +1 -1
- data/pages/Encoding.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +9 -3
- data/pages/Options.md +62 -12
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +73 -22
- metadata +68 -192
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -27
- 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/decoding_test.rb +0 -125
- data/test/activesupport5/encoding_test.rb +0 -485
- data/test/activesupport5/encoding_test_cases.rb +0 -90
- data/test/activesupport5/test_helper.rb +0 -50
- data/test/activesupport5/time_zone_test_helpers.rb +0 -24
- data/test/bar.rb +0 -25
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -21
- data/test/helper.rb +0 -26
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -148
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -383
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -470
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -18
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -151
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -145
- data/test/perf_wab.rb +0 -131
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -509
- data/test/test_custom.rb +0 -503
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -470
- data/test/test_file.rb +0 -239
- data/test/test_gc.rb +0 -49
- data/test/test_hash.rb +0 -29
- data/test/test_integer_range.rb +0 -73
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1018
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -433
- data/test/test_strict.rb +0 -410
- data/test/test_various.rb +0 -741
- data/test/test_wab.rb +0 -307
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -24
- data/test/tests_mimic.rb +0 -14
- data/test/tests_mimic_addition.rb +0 -7
- data/test/zoo.rb +0 -13
data/pages/Rails.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# Rails Quickstart
|
2
|
+
|
3
|
+
To universally replace Rails' use of the json gem with Oj, and also
|
4
|
+
have Oj "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
|
5
|
+
their faster Oj counterparts, add this to an initializer:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
Oj.optimize_rails()
|
9
|
+
```
|
10
|
+
|
11
|
+
For more details and options, read on...
|
12
|
+
|
1
13
|
# Oj Rails Compatibility
|
2
14
|
|
3
15
|
The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
|
@@ -26,44 +38,44 @@ directly. If Rails mode is also desired then use the `Oj.default_options` to
|
|
26
38
|
change the default mode.
|
27
39
|
|
28
40
|
Some of the Oj options are supported as arguments to the encoder if called
|
29
|
-
from Oj::Rails.encode() but when using the Oj::Rails::Encoder class the
|
30
|
-
encode() method does not support optional arguments as required by the
|
41
|
+
from `Oj::Rails.encode()` but when using the `Oj::Rails::Encoder` class the
|
42
|
+
`encode()` method does not support optional arguments as required by the
|
31
43
|
ActiveSupport compliance guidelines. The general approach Rails takes for
|
32
44
|
configuring encoding options is to either set global values or to create a new
|
33
45
|
instance of the Encoder class and provide options in the initializer.
|
34
46
|
|
35
47
|
The globals that ActiveSupport uses for encoding are:
|
36
48
|
|
37
|
-
* ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
38
|
-
* ActiveSupport::JSON::Encoding.escape_html_entities_in_json
|
39
|
-
* ActiveSupport::JSON::Encoding.time_precision
|
40
|
-
* ActiveSupport::JSON::Encoding.json_encoder
|
49
|
+
* `ActiveSupport::JSON::Encoding.use_standard_json_time_format`
|
50
|
+
* `ActiveSupport::JSON::Encoding.escape_html_entities_in_json`
|
51
|
+
* `ActiveSupport::JSON::Encoding.time_precision`
|
52
|
+
* `ActiveSupport::JSON::Encoding.json_encoder`
|
41
53
|
|
42
54
|
Those globals are aliased to also be accessed from the ActiveSupport module
|
43
|
-
directly so ActiveSupport::JSON::Encoding.time_precision can also be accessed
|
44
|
-
from ActiveSupport.time_precision
|
45
|
-
Rails after the Oj::Rails.set_encode() method is called. That also sets the
|
46
|
-
ActiveSupport.json_encoder to the Oj::Rails::Encoder class.
|
55
|
+
directly so `ActiveSupport::JSON::Encoding.time_precision` can also be accessed
|
56
|
+
from `ActiveSupport.time_precision`. Oj makes use of these globals in mimicking
|
57
|
+
Rails after the `Oj::Rails.set_encode()` method is called. That also sets the
|
58
|
+
`ActiveSupport.json_encoder` to the `Oj::Rails::Encoder` class.
|
47
59
|
|
48
|
-
Options passed into a call to to_json() are passed to the as_json()
|
60
|
+
Options passed into a call to `to_json()` are passed to the `as_json()`
|
49
61
|
methods. These are mostly ignored by Oj and simply passed on without
|
50
62
|
modifications as per the guidelines. The exception to this are the options
|
51
|
-
specific to Oj such as the
|
63
|
+
specific to Oj such as the `:circular` option which it used to detect circular
|
52
64
|
references while encoding.
|
53
65
|
|
54
66
|
By default Oj acts like the ActiveSupport encoder and honors any changes in
|
55
|
-
the as_json() methods. There are some optimized Oj encoders for some
|
56
|
-
classes. When the optimized encoder it toggled the as_json() methods will not
|
67
|
+
the `as_json()` methods. There are some optimized Oj encoders for some
|
68
|
+
classes. When the optimized encoder it toggled the `as_json()` methods will not
|
57
69
|
be called for that class but instead the optimized version will be called. The
|
58
70
|
optimized version is the same as the ActiveSupport default encoding for a
|
59
|
-
given class. The optimized versions are toggled with the optimize() and
|
60
|
-
deoptimize() methods. There is a default optimized version for every class
|
71
|
+
given class. The optimized versions are toggled with the `optimize()` and
|
72
|
+
`deoptimize()` methods. There is a default optimized version for every class
|
61
73
|
that takes the visible attributes and encodes them but that may not be the
|
62
74
|
same as what Rails uses. Trial and error is the best approach for classes not
|
63
75
|
listed here.
|
64
76
|
|
65
77
|
The classes that can be put in optimized mode and are optimized when
|
66
|
-
Oj::Rails.optimize is called with no arguments are:
|
78
|
+
`Oj::Rails.optimize` is called with no arguments are:
|
67
79
|
|
68
80
|
* Array
|
69
81
|
* BigDecimal
|
@@ -77,8 +89,47 @@ Oj::Rails.optimize is called with no arguments are:
|
|
77
89
|
* any class inheriting from ActiveRecord::Base
|
78
90
|
* any other class where all attributes should be dumped
|
79
91
|
|
80
|
-
The ActiveSupport decoder is the JSON.parse() method. Calling the
|
81
|
-
Oj::Rails.set_decoder() method replaces that method with the Oj equivalent.
|
92
|
+
The ActiveSupport decoder is the `JSON.parse()` method. Calling the
|
93
|
+
`Oj::Rails.set_decoder()` method replaces that method with the Oj equivalent.
|
94
|
+
|
95
|
+
### Usage in Rails 3
|
96
|
+
|
97
|
+
To support Rails 3 you can create a new module mixin to prepend to controllers:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
require 'oj'
|
101
|
+
|
102
|
+
module OjJsonEncoder
|
103
|
+
def render(options = nil, extra_options = {}, &block)
|
104
|
+
if options && options.is_a?(Hash) && options[:json]
|
105
|
+
obj = options.delete(:json)
|
106
|
+
obj = Oj.dump(obj, :mode => :rails) unless obj.is_a?(String)
|
107
|
+
options[:text] = obj
|
108
|
+
response.content_type ||= Mime::JSON
|
109
|
+
end
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
Usage:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class MyController < ApplicationController
|
119
|
+
prepend OjJsonEncoder
|
120
|
+
def index
|
121
|
+
render :json => { :hello => 'world' }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
### Older Ruby Version Support (Pre 2.3.0)
|
127
|
+
|
128
|
+
If you are using an older version of Ruby, you can pin `oj` to an earlier version in your Gemfile:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
gem 'oj', '3.7.12'
|
132
|
+
```
|
82
133
|
|
83
134
|
### Notes:
|
84
135
|
|
@@ -86,9 +137,9 @@ Oj::Rails.set_decoder() method replaces that method with the Oj equivalent.
|
|
86
137
|
Ruby which is used by the json gem and by Rails. Ruby varies the
|
87
138
|
significant digits which can be either 16 or 17 depending on the value.
|
88
139
|
|
89
|
-
2. Optimized
|
90
|
-
an example, a non-String object that has a to_s() method will become the
|
91
|
-
return value of the to_s() method in the output without checking to see if
|
140
|
+
2. Optimized Hashes do not collapse keys that become the same in the output. As
|
141
|
+
an example, a non-String object that has a `to_s()` method will become the
|
142
|
+
return value of the `to_s()` method in the output without checking to see if
|
92
143
|
that has already been used. This could occur is a mix of String and Symbols
|
93
144
|
are used as keys or if a other non-String objects such as Numerics are mixed
|
94
145
|
with numbers as Strings.
|
metadata
CHANGED
@@ -1,35 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.16.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: bigdecimal
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2.0'
|
23
|
-
type: :development
|
18
|
+
version: '3.0'
|
19
|
+
type: :runtime
|
24
20
|
prerelease: false
|
25
21
|
version_requirements: !ruby/object:Gem::Requirement
|
26
22
|
requirements:
|
27
23
|
- - ">="
|
28
24
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0
|
30
|
-
|
25
|
+
version: '3.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: ostruct
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '2
|
32
|
+
version: '0.2'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.2'
|
33
40
|
- !ruby/object:Gem::Dependency
|
34
41
|
name: minitest
|
35
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,33 +52,39 @@ dependencies:
|
|
45
52
|
- !ruby/object:Gem::Version
|
46
53
|
version: '5'
|
47
54
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
55
|
+
name: rake-compiler
|
49
56
|
requirement: !ruby/object:Gem::Requirement
|
50
57
|
requirements:
|
51
|
-
- - "
|
58
|
+
- - ">="
|
52
59
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
60
|
+
version: '0.9'
|
61
|
+
- - "<"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.0'
|
54
64
|
type: :development
|
55
65
|
prerelease: false
|
56
66
|
version_requirements: !ruby/object:Gem::Requirement
|
57
67
|
requirements:
|
58
|
-
- - "
|
68
|
+
- - ">="
|
59
69
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
70
|
+
version: '0.9'
|
71
|
+
- - "<"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '2.0'
|
61
74
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
75
|
+
name: test-unit
|
63
76
|
requirement: !ruby/object:Gem::Requirement
|
64
77
|
requirements:
|
65
78
|
- - "~>"
|
66
79
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
80
|
+
version: '3.0'
|
68
81
|
type: :development
|
69
82
|
prerelease: false
|
70
83
|
version_requirements: !ruby/object:Gem::Requirement
|
71
84
|
requirements:
|
72
85
|
- - "~>"
|
73
86
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
87
|
+
version: '3.0'
|
75
88
|
description: The fastest JSON parser and object serializer.
|
76
89
|
email: peter@ohler.com
|
77
90
|
executables: []
|
@@ -79,20 +92,29 @@ extensions:
|
|
79
92
|
- ext/oj/extconf.rb
|
80
93
|
extra_rdoc_files:
|
81
94
|
- README.md
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
- pages/WAB.md
|
86
|
-
- pages/Custom.md
|
95
|
+
- LICENSE
|
96
|
+
- CHANGELOG.md
|
97
|
+
- RELEASE_NOTES.md
|
87
98
|
- pages/Advanced.md
|
88
|
-
- pages/Options.md
|
89
99
|
- pages/Compatibility.md
|
100
|
+
- pages/Custom.md
|
101
|
+
- pages/Encoding.md
|
102
|
+
- pages/InstallOptions.md
|
103
|
+
- pages/JsonGem.md
|
90
104
|
- pages/Modes.md
|
105
|
+
- pages/Options.md
|
106
|
+
- pages/Parser.md
|
107
|
+
- pages/Rails.md
|
91
108
|
- pages/Security.md
|
109
|
+
- pages/WAB.md
|
92
110
|
files:
|
111
|
+
- CHANGELOG.md
|
93
112
|
- LICENSE
|
94
113
|
- README.md
|
114
|
+
- RELEASE_NOTES.md
|
95
115
|
- ext/oj/buf.h
|
116
|
+
- ext/oj/cache.c
|
117
|
+
- ext/oj/cache.h
|
96
118
|
- ext/oj/cache8.c
|
97
119
|
- ext/oj/cache8.h
|
98
120
|
- ext/oj/circarray.c
|
@@ -101,6 +123,7 @@ files:
|
|
101
123
|
- ext/oj/code.h
|
102
124
|
- ext/oj/compat.c
|
103
125
|
- ext/oj/custom.c
|
126
|
+
- ext/oj/debug.c
|
104
127
|
- ext/oj/dump.c
|
105
128
|
- ext/oj/dump.h
|
106
129
|
- ext/oj/dump_compat.c
|
@@ -108,13 +131,15 @@ files:
|
|
108
131
|
- ext/oj/dump_object.c
|
109
132
|
- ext/oj/dump_strict.c
|
110
133
|
- ext/oj/encode.h
|
134
|
+
- ext/oj/encoder.c
|
111
135
|
- ext/oj/err.c
|
112
136
|
- ext/oj/err.h
|
113
137
|
- ext/oj/extconf.rb
|
114
138
|
- ext/oj/fast.c
|
115
|
-
- ext/oj/
|
116
|
-
- ext/oj/
|
117
|
-
- ext/oj/
|
139
|
+
- ext/oj/intern.c
|
140
|
+
- ext/oj/intern.h
|
141
|
+
- ext/oj/mem.c
|
142
|
+
- ext/oj/mem.h
|
118
143
|
- ext/oj/mimic_json.c
|
119
144
|
- ext/oj/object.c
|
120
145
|
- ext/oj/odd.c
|
@@ -123,6 +148,8 @@ files:
|
|
123
148
|
- ext/oj/oj.h
|
124
149
|
- ext/oj/parse.c
|
125
150
|
- ext/oj/parse.h
|
151
|
+
- ext/oj/parser.c
|
152
|
+
- ext/oj/parser.h
|
126
153
|
- ext/oj/rails.c
|
127
154
|
- ext/oj/rails.h
|
128
155
|
- ext/oj/reader.c
|
@@ -132,17 +159,23 @@ files:
|
|
132
159
|
- ext/oj/rxclass.c
|
133
160
|
- ext/oj/rxclass.h
|
134
161
|
- ext/oj/saj.c
|
162
|
+
- ext/oj/saj2.c
|
163
|
+
- ext/oj/saj2.h
|
135
164
|
- ext/oj/scp.c
|
165
|
+
- ext/oj/simd.h
|
136
166
|
- ext/oj/sparse.c
|
137
167
|
- ext/oj/stream_writer.c
|
138
168
|
- ext/oj/strict.c
|
139
169
|
- ext/oj/string_writer.c
|
140
170
|
- ext/oj/trace.c
|
141
171
|
- ext/oj/trace.h
|
172
|
+
- ext/oj/usual.c
|
173
|
+
- ext/oj/usual.h
|
142
174
|
- ext/oj/util.c
|
143
175
|
- ext/oj/util.h
|
144
176
|
- ext/oj/val_stack.c
|
145
177
|
- ext/oj/val_stack.h
|
178
|
+
- ext/oj/validate.c
|
146
179
|
- ext/oj/wab.c
|
147
180
|
- lib/oj.rb
|
148
181
|
- lib/oj/active_support_helper.rb
|
@@ -159,91 +192,14 @@ files:
|
|
159
192
|
- pages/Compatibility.md
|
160
193
|
- pages/Custom.md
|
161
194
|
- pages/Encoding.md
|
195
|
+
- pages/InstallOptions.md
|
162
196
|
- pages/JsonGem.md
|
163
197
|
- pages/Modes.md
|
164
198
|
- pages/Options.md
|
199
|
+
- pages/Parser.md
|
165
200
|
- pages/Rails.md
|
166
201
|
- pages/Security.md
|
167
202
|
- pages/WAB.md
|
168
|
-
- test/_test_active.rb
|
169
|
-
- test/_test_active_mimic.rb
|
170
|
-
- test/_test_mimic_rails.rb
|
171
|
-
- test/activerecord/result_test.rb
|
172
|
-
- test/activesupport4/decoding_test.rb
|
173
|
-
- test/activesupport4/encoding_test.rb
|
174
|
-
- test/activesupport4/test_helper.rb
|
175
|
-
- test/activesupport5/decoding_test.rb
|
176
|
-
- test/activesupport5/encoding_test.rb
|
177
|
-
- test/activesupport5/encoding_test_cases.rb
|
178
|
-
- test/activesupport5/test_helper.rb
|
179
|
-
- test/activesupport5/time_zone_test_helpers.rb
|
180
|
-
- test/bar.rb
|
181
|
-
- test/files.rb
|
182
|
-
- test/foo.rb
|
183
|
-
- test/helper.rb
|
184
|
-
- test/isolated/shared.rb
|
185
|
-
- test/isolated/test_mimic_after.rb
|
186
|
-
- test/isolated/test_mimic_alone.rb
|
187
|
-
- test/isolated/test_mimic_as_json.rb
|
188
|
-
- test/isolated/test_mimic_before.rb
|
189
|
-
- test/isolated/test_mimic_define.rb
|
190
|
-
- test/isolated/test_mimic_rails_after.rb
|
191
|
-
- test/isolated/test_mimic_rails_before.rb
|
192
|
-
- test/isolated/test_mimic_redefine.rb
|
193
|
-
- test/json_gem/json_addition_test.rb
|
194
|
-
- test/json_gem/json_common_interface_test.rb
|
195
|
-
- test/json_gem/json_encoding_test.rb
|
196
|
-
- test/json_gem/json_ext_parser_test.rb
|
197
|
-
- test/json_gem/json_fixtures_test.rb
|
198
|
-
- test/json_gem/json_generator_test.rb
|
199
|
-
- test/json_gem/json_generic_object_test.rb
|
200
|
-
- test/json_gem/json_parser_test.rb
|
201
|
-
- test/json_gem/json_string_matching_test.rb
|
202
|
-
- test/json_gem/test_helper.rb
|
203
|
-
- test/perf.rb
|
204
|
-
- test/perf_compat.rb
|
205
|
-
- test/perf_fast.rb
|
206
|
-
- test/perf_file.rb
|
207
|
-
- test/perf_object.rb
|
208
|
-
- test/perf_saj.rb
|
209
|
-
- test/perf_scp.rb
|
210
|
-
- test/perf_simple.rb
|
211
|
-
- test/perf_strict.rb
|
212
|
-
- test/perf_wab.rb
|
213
|
-
- test/sample.rb
|
214
|
-
- test/sample/change.rb
|
215
|
-
- test/sample/dir.rb
|
216
|
-
- test/sample/doc.rb
|
217
|
-
- test/sample/file.rb
|
218
|
-
- test/sample/group.rb
|
219
|
-
- test/sample/hasprops.rb
|
220
|
-
- test/sample/layer.rb
|
221
|
-
- test/sample/line.rb
|
222
|
-
- test/sample/oval.rb
|
223
|
-
- test/sample/rect.rb
|
224
|
-
- test/sample/shape.rb
|
225
|
-
- test/sample/text.rb
|
226
|
-
- test/sample_json.rb
|
227
|
-
- test/test_compat.rb
|
228
|
-
- test/test_custom.rb
|
229
|
-
- test/test_debian.rb
|
230
|
-
- test/test_fast.rb
|
231
|
-
- test/test_file.rb
|
232
|
-
- test/test_gc.rb
|
233
|
-
- test/test_hash.rb
|
234
|
-
- test/test_integer_range.rb
|
235
|
-
- test/test_null.rb
|
236
|
-
- test/test_object.rb
|
237
|
-
- test/test_saj.rb
|
238
|
-
- test/test_scp.rb
|
239
|
-
- test/test_strict.rb
|
240
|
-
- test/test_various.rb
|
241
|
-
- test/test_wab.rb
|
242
|
-
- test/test_writer.rb
|
243
|
-
- test/tests.rb
|
244
|
-
- test/tests_mimic.rb
|
245
|
-
- test/tests_mimic_addition.rb
|
246
|
-
- test/zoo.rb
|
247
203
|
homepage: http://www.ohler.com/oj
|
248
204
|
licenses:
|
249
205
|
- MIT
|
@@ -254,7 +210,7 @@ metadata:
|
|
254
210
|
homepage_uri: http://www.ohler.com/oj/
|
255
211
|
source_code_uri: https://github.com/ohler55/oj
|
256
212
|
wiki_uri: https://github.com/ohler55/oj/wiki
|
257
|
-
|
213
|
+
rubygems_mfa_required: 'true'
|
258
214
|
rdoc_options:
|
259
215
|
- "--title"
|
260
216
|
- Oj
|
@@ -266,94 +222,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
266
222
|
requirements:
|
267
223
|
- - ">="
|
268
224
|
- !ruby/object:Gem::Version
|
269
|
-
version: '2.
|
225
|
+
version: '2.7'
|
270
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
271
227
|
requirements:
|
272
228
|
- - ">="
|
273
229
|
- !ruby/object:Gem::Version
|
274
230
|
version: '0'
|
275
231
|
requirements: []
|
276
|
-
rubygems_version: 3.
|
277
|
-
signing_key:
|
232
|
+
rubygems_version: 3.6.2
|
278
233
|
specification_version: 4
|
279
234
|
summary: A fast JSON parser and serializer.
|
280
|
-
test_files:
|
281
|
-
- test/foo.rb
|
282
|
-
- test/test_integer_range.rb
|
283
|
-
- test/test_strict.rb
|
284
|
-
- test/perf_strict.rb
|
285
|
-
- test/tests.rb
|
286
|
-
- test/perf_saj.rb
|
287
|
-
- test/test_compat.rb
|
288
|
-
- test/helper.rb
|
289
|
-
- test/perf_file.rb
|
290
|
-
- test/test_scp.rb
|
291
|
-
- test/perf_compat.rb
|
292
|
-
- test/json_gem/json_common_interface_test.rb
|
293
|
-
- test/json_gem/json_addition_test.rb
|
294
|
-
- test/json_gem/json_fixtures_test.rb
|
295
|
-
- test/json_gem/json_ext_parser_test.rb
|
296
|
-
- test/json_gem/json_string_matching_test.rb
|
297
|
-
- test/json_gem/json_generic_object_test.rb
|
298
|
-
- test/json_gem/json_generator_test.rb
|
299
|
-
- test/json_gem/test_helper.rb
|
300
|
-
- test/json_gem/json_encoding_test.rb
|
301
|
-
- test/json_gem/json_parser_test.rb
|
302
|
-
- test/perf_wab.rb
|
303
|
-
- test/test_file.rb
|
304
|
-
- test/test_object.rb
|
305
|
-
- test/sample.rb
|
306
|
-
- test/perf_object.rb
|
307
|
-
- test/test_hash.rb
|
308
|
-
- test/test_custom.rb
|
309
|
-
- test/bar.rb
|
310
|
-
- test/activesupport4/encoding_test.rb
|
311
|
-
- test/activesupport4/test_helper.rb
|
312
|
-
- test/activesupport4/decoding_test.rb
|
313
|
-
- test/sample_json.rb
|
314
|
-
- test/activesupport5/encoding_test_cases.rb
|
315
|
-
- test/activesupport5/encoding_test.rb
|
316
|
-
- test/activesupport5/time_zone_test_helpers.rb
|
317
|
-
- test/activesupport5/test_helper.rb
|
318
|
-
- test/activesupport5/decoding_test.rb
|
319
|
-
- test/test_saj.rb
|
320
|
-
- test/perf_scp.rb
|
321
|
-
- test/test_wab.rb
|
322
|
-
- test/test_null.rb
|
323
|
-
- test/_test_active.rb
|
324
|
-
- test/_test_mimic_rails.rb
|
325
|
-
- test/test_fast.rb
|
326
|
-
- test/perf_fast.rb
|
327
|
-
- test/sample/change.rb
|
328
|
-
- test/sample/text.rb
|
329
|
-
- test/sample/doc.rb
|
330
|
-
- test/sample/shape.rb
|
331
|
-
- test/sample/layer.rb
|
332
|
-
- test/sample/group.rb
|
333
|
-
- test/sample/file.rb
|
334
|
-
- test/sample/rect.rb
|
335
|
-
- test/sample/hasprops.rb
|
336
|
-
- test/sample/line.rb
|
337
|
-
- test/sample/dir.rb
|
338
|
-
- test/sample/oval.rb
|
339
|
-
- test/tests_mimic.rb
|
340
|
-
- test/perf_simple.rb
|
341
|
-
- test/zoo.rb
|
342
|
-
- test/activerecord/result_test.rb
|
343
|
-
- test/_test_active_mimic.rb
|
344
|
-
- test/tests_mimic_addition.rb
|
345
|
-
- test/test_writer.rb
|
346
|
-
- test/perf.rb
|
347
|
-
- test/isolated/test_mimic_define.rb
|
348
|
-
- test/isolated/test_mimic_after.rb
|
349
|
-
- test/isolated/test_mimic_rails_after.rb
|
350
|
-
- test/isolated/test_mimic_before.rb
|
351
|
-
- test/isolated/test_mimic_rails_before.rb
|
352
|
-
- test/isolated/test_mimic_redefine.rb
|
353
|
-
- test/isolated/shared.rb
|
354
|
-
- test/isolated/test_mimic_alone.rb
|
355
|
-
- test/isolated/test_mimic_as_json.rb
|
356
|
-
- test/test_debian.rb
|
357
|
-
- test/test_gc.rb
|
358
|
-
- test/files.rb
|
359
|
-
- test/test_various.rb
|
235
|
+
test_files: []
|
data/ext/oj/hash.c
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
/* hash.c
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
30
|
-
|
31
|
-
#include "hash.h"
|
32
|
-
#include <stdint.h>
|
33
|
-
|
34
|
-
#define HASH_MASK 0x000003FF
|
35
|
-
#define HASH_SLOT_CNT 1024
|
36
|
-
|
37
|
-
typedef struct _keyVal {
|
38
|
-
struct _keyVal *next;
|
39
|
-
const char *key;
|
40
|
-
size_t len;
|
41
|
-
VALUE val;
|
42
|
-
} *KeyVal;
|
43
|
-
|
44
|
-
struct _hash {
|
45
|
-
struct _keyVal slots[HASH_SLOT_CNT];
|
46
|
-
};
|
47
|
-
|
48
|
-
struct _hash class_hash;
|
49
|
-
struct _hash intern_hash;
|
50
|
-
|
51
|
-
// almost the Murmur hash algorithm
|
52
|
-
#define M 0x5bd1e995
|
53
|
-
#define C1 0xCC9E2D51
|
54
|
-
#define C2 0x1B873593
|
55
|
-
#define N 0xE6546B64
|
56
|
-
|
57
|
-
static uint32_t
|
58
|
-
hash_calc(const uint8_t *key, size_t len) {
|
59
|
-
const uint8_t *end = key + len;
|
60
|
-
const uint8_t *endless = key + (len / 4 * 4);
|
61
|
-
uint32_t h = (uint32_t)len;
|
62
|
-
uint32_t k;
|
63
|
-
|
64
|
-
while (key < endless) {
|
65
|
-
k = (uint32_t)*key++;
|
66
|
-
k |= (uint32_t)*key++ << 8;
|
67
|
-
k |= (uint32_t)*key++ << 16;
|
68
|
-
k |= (uint32_t)*key++ << 24;
|
69
|
-
|
70
|
-
k *= M;
|
71
|
-
k ^= k >> 24;
|
72
|
-
h *= M;
|
73
|
-
h ^= k * M;
|
74
|
-
}
|
75
|
-
if (1 < end - key) {
|
76
|
-
uint16_t k16 = (uint16_t)*key++;
|
77
|
-
|
78
|
-
k16 |= (uint16_t)*key++ << 8;
|
79
|
-
h ^= k16 << 8;
|
80
|
-
}
|
81
|
-
if (key < end) {
|
82
|
-
h ^= *key;
|
83
|
-
}
|
84
|
-
h *= M;
|
85
|
-
h ^= h >> 13;
|
86
|
-
h *= M;
|
87
|
-
h ^= h >> 15;
|
88
|
-
|
89
|
-
return h;
|
90
|
-
}
|
91
|
-
|
92
|
-
void
|
93
|
-
oj_hash_init() {
|
94
|
-
memset(class_hash.slots, 0, sizeof(class_hash.slots));
|
95
|
-
memset(intern_hash.slots, 0, sizeof(intern_hash.slots));
|
96
|
-
}
|
97
|
-
|
98
|
-
// if slotp is 0 then just lookup
|
99
|
-
static VALUE
|
100
|
-
hash_get(Hash hash, const char *key, size_t len, VALUE **slotp, VALUE def_value) {
|
101
|
-
uint32_t h = hash_calc((const uint8_t*)key, len) & HASH_MASK;
|
102
|
-
KeyVal bucket = hash->slots + h;
|
103
|
-
|
104
|
-
if (0 != bucket->key) {
|
105
|
-
KeyVal b;
|
106
|
-
|
107
|
-
for (b = bucket; 0 != b; b = b->next) {
|
108
|
-
if (len == b->len && 0 == strncmp(b->key, key, len)) {
|
109
|
-
*slotp = &b->val;
|
110
|
-
return b->val;
|
111
|
-
}
|
112
|
-
bucket = b;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
if (0 != slotp) {
|
116
|
-
if (0 != bucket->key) {
|
117
|
-
KeyVal b = ALLOC(struct _keyVal);
|
118
|
-
|
119
|
-
b->next = 0;
|
120
|
-
bucket->next = b;
|
121
|
-
bucket = b;
|
122
|
-
}
|
123
|
-
bucket->key = oj_strndup(key, len);
|
124
|
-
bucket->len = len;
|
125
|
-
bucket->val = def_value;
|
126
|
-
*slotp = &bucket->val;
|
127
|
-
}
|
128
|
-
return def_value;
|
129
|
-
}
|
130
|
-
|
131
|
-
void
|
132
|
-
oj_hash_print() {
|
133
|
-
int i;
|
134
|
-
KeyVal b;
|
135
|
-
|
136
|
-
for (i = 0; i < HASH_SLOT_CNT; i++) {
|
137
|
-
printf("%4d:", i);
|
138
|
-
for (b = class_hash.slots + i; 0 != b && 0 != b->key; b = b->next) {
|
139
|
-
printf(" %s", b->key);
|
140
|
-
}
|
141
|
-
printf("\n");
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
VALUE
|
146
|
-
oj_class_hash_get(const char *key, size_t len, VALUE **slotp) {
|
147
|
-
return hash_get(&class_hash, key, len, slotp, Qnil);
|
148
|
-
}
|
149
|
-
|
150
|
-
ID
|
151
|
-
oj_attr_hash_get(const char *key, size_t len, ID **slotp) {
|
152
|
-
return (ID)hash_get(&intern_hash, key, len, (VALUE**)slotp, 0);
|
153
|
-
}
|
154
|
-
|
155
|
-
char*
|
156
|
-
oj_strndup(const char *s, size_t len) {
|
157
|
-
char *d = ALLOC_N(char, len + 1);
|
158
|
-
|
159
|
-
memcpy(d, s, len);
|
160
|
-
d[len] = '\0';
|
161
|
-
|
162
|
-
return d;
|
163
|
-
}
|