oj 2.18.5 → 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.
Files changed (166) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1452 -0
  3. data/README.md +53 -221
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +54 -72
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +61 -63
  9. data/ext/oj/cache8.h +12 -39
  10. data/ext/oj/circarray.c +38 -67
  11. data/ext/oj/circarray.h +16 -42
  12. data/ext/oj/code.c +214 -0
  13. data/ext/oj/code.h +40 -0
  14. data/ext/oj/compat.c +194 -110
  15. data/ext/oj/custom.c +1074 -0
  16. data/ext/oj/debug.c +126 -0
  17. data/ext/oj/dump.c +1276 -2494
  18. data/ext/oj/dump.h +110 -0
  19. data/ext/oj/dump_compat.c +897 -0
  20. data/ext/oj/dump_leaf.c +162 -0
  21. data/ext/oj/dump_object.c +710 -0
  22. data/ext/oj/dump_strict.c +399 -0
  23. data/ext/oj/encode.h +7 -42
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +28 -53
  26. data/ext/oj/err.h +49 -46
  27. data/ext/oj/extconf.rb +33 -32
  28. data/ext/oj/fast.c +1082 -1098
  29. data/ext/oj/intern.c +313 -0
  30. data/ext/oj/intern.h +22 -0
  31. data/ext/oj/mem.c +318 -0
  32. data/ext/oj/mem.h +53 -0
  33. data/ext/oj/mimic_json.c +919 -0
  34. data/ext/oj/object.c +545 -625
  35. data/ext/oj/odd.c +158 -168
  36. data/ext/oj/odd.h +32 -58
  37. data/ext/oj/oj.c +1727 -2080
  38. data/ext/oj/oj.h +334 -259
  39. data/ext/oj/parse.c +974 -753
  40. data/ext/oj/parse.h +97 -90
  41. data/ext/oj/parser.c +1600 -0
  42. data/ext/oj/parser.h +103 -0
  43. data/ext/oj/rails.c +1478 -0
  44. data/ext/oj/rails.h +18 -0
  45. data/ext/oj/reader.c +136 -163
  46. data/ext/oj/reader.h +76 -112
  47. data/ext/oj/resolve.c +45 -94
  48. data/ext/oj/resolve.h +7 -34
  49. data/ext/oj/rxclass.c +144 -0
  50. data/ext/oj/rxclass.h +26 -0
  51. data/ext/oj/saj.c +445 -511
  52. data/ext/oj/saj2.c +584 -0
  53. data/ext/oj/saj2.h +23 -0
  54. data/ext/oj/scp.c +82 -143
  55. data/ext/oj/simd.h +10 -0
  56. data/ext/oj/sparse.c +749 -644
  57. data/ext/oj/stream_writer.c +329 -0
  58. data/ext/oj/strict.c +114 -112
  59. data/ext/oj/string_writer.c +517 -0
  60. data/ext/oj/trace.c +72 -0
  61. data/ext/oj/trace.h +55 -0
  62. data/ext/oj/usual.c +1218 -0
  63. data/ext/oj/usual.h +69 -0
  64. data/ext/oj/util.c +136 -0
  65. data/ext/oj/util.h +20 -0
  66. data/ext/oj/val_stack.c +75 -72
  67. data/ext/oj/val_stack.h +94 -127
  68. data/ext/oj/validate.c +46 -0
  69. data/ext/oj/wab.c +586 -0
  70. data/lib/oj/active_support_helper.rb +1 -3
  71. data/lib/oj/bag.rb +8 -1
  72. data/lib/oj/easy_hash.rb +21 -13
  73. data/lib/oj/error.rb +10 -12
  74. data/lib/oj/json.rb +188 -0
  75. data/lib/oj/mimic.rb +165 -26
  76. data/lib/oj/saj.rb +20 -6
  77. data/lib/oj/schandler.rb +5 -4
  78. data/lib/oj/state.rb +135 -0
  79. data/lib/oj/version.rb +2 -3
  80. data/lib/oj.rb +3 -31
  81. data/pages/Advanced.md +22 -0
  82. data/pages/Compatibility.md +25 -0
  83. data/pages/Custom.md +23 -0
  84. data/pages/Encoding.md +65 -0
  85. data/pages/InstallOptions.md +20 -0
  86. data/pages/JsonGem.md +94 -0
  87. data/pages/Modes.md +161 -0
  88. data/pages/Options.md +337 -0
  89. data/pages/Parser.md +309 -0
  90. data/pages/Rails.md +167 -0
  91. data/pages/Security.md +20 -0
  92. data/pages/WAB.md +13 -0
  93. metadata +126 -163
  94. data/ext/oj/hash.c +0 -163
  95. data/ext/oj/hash.h +0 -46
  96. data/ext/oj/hash_test.c +0 -512
  97. data/test/_test_active.rb +0 -76
  98. data/test/_test_active_mimic.rb +0 -96
  99. data/test/_test_mimic_rails.rb +0 -126
  100. data/test/activesupport_datetime_test.rb +0 -23
  101. data/test/bug.rb +0 -51
  102. data/test/bug2.rb +0 -10
  103. data/test/bug3.rb +0 -46
  104. data/test/bug_fast.rb +0 -32
  105. data/test/bug_load.rb +0 -24
  106. data/test/crash.rb +0 -111
  107. data/test/curl/curl_oj.rb +0 -46
  108. data/test/curl/get_oj.rb +0 -24
  109. data/test/curl/just_curl.rb +0 -31
  110. data/test/curl/just_oj.rb +0 -51
  111. data/test/example.rb +0 -11
  112. data/test/files.rb +0 -29
  113. data/test/foo.rb +0 -24
  114. data/test/helper.rb +0 -27
  115. data/test/io.rb +0 -48
  116. data/test/isolated/shared.rb +0 -310
  117. data/test/isolated/test_mimic_after.rb +0 -13
  118. data/test/isolated/test_mimic_alone.rb +0 -12
  119. data/test/isolated/test_mimic_as_json.rb +0 -45
  120. data/test/isolated/test_mimic_before.rb +0 -13
  121. data/test/isolated/test_mimic_define.rb +0 -28
  122. data/test/isolated/test_mimic_rails_after.rb +0 -22
  123. data/test/isolated/test_mimic_rails_before.rb +0 -21
  124. data/test/isolated/test_mimic_rails_datetime.rb +0 -27
  125. data/test/isolated/test_mimic_redefine.rb +0 -15
  126. data/test/mod.rb +0 -16
  127. data/test/perf.rb +0 -107
  128. data/test/perf_compat.rb +0 -128
  129. data/test/perf_fast.rb +0 -164
  130. data/test/perf_file.rb +0 -64
  131. data/test/perf_object.rb +0 -138
  132. data/test/perf_saj.rb +0 -109
  133. data/test/perf_scp.rb +0 -151
  134. data/test/perf_simple.rb +0 -287
  135. data/test/perf_strict.rb +0 -128
  136. data/test/rails.rb +0 -50
  137. data/test/russian.rb +0 -18
  138. data/test/sample/change.rb +0 -14
  139. data/test/sample/dir.rb +0 -19
  140. data/test/sample/doc.rb +0 -36
  141. data/test/sample/file.rb +0 -48
  142. data/test/sample/group.rb +0 -16
  143. data/test/sample/hasprops.rb +0 -16
  144. data/test/sample/layer.rb +0 -12
  145. data/test/sample/line.rb +0 -20
  146. data/test/sample/oval.rb +0 -10
  147. data/test/sample/rect.rb +0 -10
  148. data/test/sample/shape.rb +0 -35
  149. data/test/sample/text.rb +0 -20
  150. data/test/sample.rb +0 -55
  151. data/test/sample_json.rb +0 -37
  152. data/test/struct.rb +0 -29
  153. data/test/test_compat.rb +0 -398
  154. data/test/test_debian.rb +0 -53
  155. data/test/test_fast.rb +0 -458
  156. data/test/test_file.rb +0 -245
  157. data/test/test_gc.rb +0 -49
  158. data/test/test_hash.rb +0 -29
  159. data/test/test_object.rb +0 -745
  160. data/test/test_saj.rb +0 -186
  161. data/test/test_scp.rb +0 -396
  162. data/test/test_serializer.rb +0 -59
  163. data/test/test_strict.rb +0 -254
  164. data/test/test_various.rb +0 -1383
  165. data/test/test_writer.rb +0 -308
  166. data/test/write_timebars.rb +0 -31
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
- # Oj gem
2
- [![Build Status](https://img.shields.io/travis/ohler55/oj/master.svg)](http://travis-ci.org/ohler55/oj?branch=master) ![Gem](https://img.shields.io/gem/v/oj.svg) ![Gem](https://img.shields.io/gem/dt/oj.svg)
1
+ # [![{}j](http://www.ohler.com/dev/images/oj_comet_64.svg)](http://www.ohler.com/oj) gem
3
2
 
4
- A fast JSON parser and Object marshaller as a Ruby gem.
3
+ [![CI](https://github.com/ohler55/oj/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/oj/actions/workflows/CI.yml)
4
+ ![Gem](https://img.shields.io/gem/v/oj.svg)
5
+ ![Gem](https://img.shields.io/gem/dt/oj.svg)
6
+ [![TideLift](https://tidelift.com/badges/github/ohler55/oj)](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
7
+
8
+ A *fast* JSON parser and Object marshaller as a Ruby gem.
9
+
10
+ Version 3.13 is out with a much faster parser (`Oj::Parser`) and option isolation.
5
11
 
6
12
  ## Using
7
13
 
@@ -25,11 +31,6 @@ puts "Same? #{h == h2}"
25
31
  # true
26
32
  ```
27
33
 
28
- By default Oj uses the :object mode which is used to marshal and unmarshal Ruby
29
- objects. Deserialize arbitrary JSON in object mode may lead to unexpected
30
- results. :compat mode is a better choice for rails and :strict mode is a better
31
- choice for general JSON parsing. See the options section below for details.
32
-
33
34
  ## Installation
34
35
  ```
35
36
  gem install oj
@@ -41,247 +42,78 @@ or in Bundler:
41
42
  gem 'oj'
42
43
  ```
43
44
 
44
- ## Advanced
45
-
46
- Optimized JSON (Oj), as the name implies, was written to provide speed optimized
47
- JSON handling. It was designed as a faster alternative to Yajl and other
48
- common Ruby JSON parsers. So far it has achieved that, and is about 2 times faster
49
- than any other Ruby JSON parser, and 3 or more times faster at serializing JSON.
50
-
51
- Oj has several `dump` or serialization modes which control how Ruby `Object`s are
52
- converted to JSON. These modes are set with the `:mode` option in either the
53
- default options or as one of the options to the `dump` method. In addition to
54
- the various options there are also alternative APIs for parsing JSON.
55
-
56
- The fastest alternative parser API is the `Oj::Doc` API. The `Oj::Doc` API takes
57
- a completely different approach by opening a JSON document and providing calls
58
- to navigate around the JSON while it is open. With this approach, JSON access
59
- can be well over 20 times faster than conventional JSON parsing.
60
-
61
- The `Oj::Saj` and `Oj::ScHandler` APIs are callback parsers that
62
- walk the JSON document depth first and makes callbacks for each element.
63
- Both callback parser are useful when only portions of the JSON are of
64
- interest. Performance up to 20 times faster than conventional JSON is
65
- possible if only a few elements of the JSON are of interest.
66
-
67
- ### Options
68
-
69
- To change default serialization mode use the following form. Attempting to
70
- modify the Oj.default_options Hash directly will not set the changes on the
71
- actual default options but on a copy of the Hash:
72
-
73
- ```ruby
74
- Oj.default_options = {:mode => :compat }
75
- ```
76
-
77
- ### Common (for serializer and parser) options
78
-
79
- * `:mode` [Symbol] mode for dumping and loading JSON. **Important format details [here](http://www.ohler.com/dev/oj_misc/encoding_format.html)**
80
-
81
- - `:object` mode will dump any `Object` as a JSON `Object` with keys that
82
- match the Ruby `Object`'s variable names without the '@' prefix
83
- character. This mode has the best performance and is the default
84
-
85
- - `:strict` mode will only allow the 7 basic JSON types to be serialized. Any
86
- other `Object` will raise an `Exception`
87
-
88
- - `:null` mode replaces any `Object` that is not one of the JSON types with a JSON `null`
89
-
90
- - `:compat` mode attempts to be compatible with other systems. It will
91
- serialize any `Object`, but will check to see if the `Object` implements an
92
- `to_hash` or `to_json` method. If either exists, that method is used for
93
- serializing the `Object`. Since `as_json` is more flexible and produces
94
- more consistent output, it is preferred over the `to_json` method. If
95
- neither the `to_json` or `to_hash` methods exists, then the Oj internal
96
- `Object` variable encoding is used
97
-
98
- * `:time_format` [Symbol] time format when dumping in :compat and :object mode
99
-
100
- - `:unix` time is output as a decimal number in seconds since epoch including
101
- fractions of a second.
102
-
103
- - `:unix_zone` similar to the `:unix` format but with the timezone encoded in
104
- the exponent of the decimal number of seconds since epoch.
105
-
106
- - `:xmlschema` time is output as a string that follows the XML schema definition.
107
-
108
- - `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
109
-
110
- * `:second_precision` [Fixnum] number of digits after the decimal when dumping
111
- the seconds portion of time
112
-
113
- * `:bigdecimal_as_decimal` [Boolean] dump BigDecimal as a decimal number
114
- or as a String
115
-
116
- * `:create_id` [String] create id for json compatible object encoding,
117
- default is `json_create`.
118
-
119
- * `:allow_gc` [Boolean] allow or prohibit GC during parsing, default is
120
- true (allow).
121
-
122
- * `:quirks_mode` [Boolean] Allow single JSON values instead of
123
- documents, default is true (allow).
124
-
125
- * `:allow_invalid_unicode` [Boolean] Allow invalid unicode, default is
126
- false (don't allow)
127
-
128
- * `:omit_nil` [Boolean] If true, Hash and Object attributes with nil values
129
- are omitted
130
-
131
- ### Serializer options
132
-
133
- * `:indent` [Fixnum] number of spaces to indent each element in an JSON
134
- document, zero is no newline between JSON elements, negative indicates no
135
- newline between top level JSON elements in a stream
136
-
137
- * `:circular` [Boolean] support circular references while dumping
138
-
139
- * `:escape_mode` [Symbol] determines the characters to escape
140
-
141
- - `:newline` allows unescaped newlines in the output
45
+ ## Rails and json quickstart
142
46
 
143
- - `:json` follows the JSON specification. This is the default mode
47
+ See the Quickstart sections of the [Rails](pages/Rails.md) and [json](pages/JsonGem.md) docs.
144
48
 
145
- - `:xss_safe` escapes HTML and XML characters such as `&` and `<`
49
+ ## multi_json
146
50
 
147
- - `:ascii` escapes all non-ascii or characters with the hi-bit set
51
+ Code which uses [multi_json](https://github.com/intridea/multi_json)
52
+ will automatically prefer Oj if it is installed.
148
53
 
149
- * `:use_to_json` [Boolean] call `to_json()` methods on dump, default is
150
- false
54
+ ## Support
151
55
 
152
- * `:use_as_json` [Boolean] call `as_json()` methods on dump, default is
153
- false
56
+ [Get supported Oj with a Tidelift Subscription.](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme) Security updates are [supported](https://tidelift.com/security).
154
57
 
155
- * `:nan` [Symbol] How to dump Infinity, -Infinity, and
156
- NaN in :null, :strict, and :compat mode. Default is :auto
58
+ ## Further Reading
157
59
 
158
- - `:null` places a null
60
+ For more details on options, modes, advanced features, and more follow these
61
+ links.
159
62
 
160
- - `:huge` places a huge number
161
-
162
- - `:word` places Infinity or NaN
163
-
164
- - `:raise` raises and exception
165
-
166
- - `:auto` uses default for each mode which are `:raise` for `:strict`, `:null` for `:null`, and `:word` for `:compat`
167
-
168
- ### Parser options
169
-
170
- * `:auto_define` [Boolean] automatically define classes if they do not
171
- exist
172
-
173
- * `:symbol_keys` [Boolean] use symbols instead of strings for hash keys
174
-
175
- * `:class_cache` [Boolean] cache classes for faster parsing (if
176
- dynamically modifying classes or reloading classes then don't use this)
177
-
178
- * `:bigdecimal_load` [Symbol] load decimals as BigDecimal instead of as a
179
- Float
180
-
181
- - `:bigdecimal` convert all decimal numbers to BigDecimal
182
-
183
- - `:float` convert all decimal numbers to Float
184
-
185
- - `:auto` the most precise for the number of digits is used
186
-
187
- * `:float_precision` [Fixnum] number of digits of precision when dumping
188
- floats, 0 indicates use Ruby
189
-
190
- * `:nilnil` [Boolean] if true a nil input to load will return nil and
191
- not raise an Exception
192
-
193
- * `:empty_string` [Boolean] if true an empty input will not raise an
194
- Exception, default is true (allow). When Oj.mimic_JSON is used,
195
- default is false (raise exception when empty string is encountered)
196
-
197
- * `:hash_class` [Class] Class to use instead of Hash on load
63
+ - [{file:Options.md}](pages/Options.md) for parse and dump options.
64
+ - [{file:Modes.md}](pages/Modes.md) for details on modes for strict JSON compliance, mimicking the JSON gem, and mimicking Rails and ActiveSupport behavior.
65
+ - [{file:JsonGem.md}](pages/JsonGem.md) includes more details on json gem compatibility and use.
66
+ - [{file:Rails.md}](pages/Rails.md) includes more details on Rails and ActiveSupport compatibility and use.
67
+ - [{file:Custom.md}](pages/Custom.md) includes more details on Custom mode.
68
+ - [{file:Encoding.md}](pages/Encoding.md) describes the :object encoding format.
69
+ - [{file:Compatibility.md}](pages/Compatibility.md) lists current compatibility with Rubys and Rails.
70
+ - [{file:Advanced.md}](pages/Advanced.md) for fast parser and marshalling features.
71
+ - [{file:Security.md}](pages/Security.md) for security considerations.
72
+ - [{file:InstallOptions.md}](pages/InstallOptions.md) for install option.
198
73
 
199
74
  ## Releases
200
75
 
201
- See [CHANGELOG.md](CHANGELOG.md)
202
-
203
- ## Compatibility
204
-
205
- **Ruby**
206
-
207
- Oj is compatible with Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4 and RBX.
208
- Support for JRuby has been removed as JRuby no longer supports C extensions and
209
- there are bugs in the older versions that are not being fixed.
210
-
211
- **Rails**
212
-
213
- Although up until 4.1 Rails uses [multi_json](https://github.com/intridea/multi_json), an [issue in Rails](https://github.com/rails/rails/issues/9212) causes ActiveSupport to fail to make use Oj for JSON handling.
214
- There is a
215
- [gem to patch this](https://github.com/GoodLife/rails-patch-json-encode) for
216
- Rails 3.2 and 4.0. As of the Oj 2.6.0 release the default behavior is to not use
217
- the `to_json()` method unless the `:use_to_json` option is set. This provides
218
- another work around to the rails older and newer behavior.
219
-
220
- The latest ActiveRecord is able to work with Oj by simply using the line:
221
-
222
- ```
223
- serialize :metadata, Oj
224
- ```
225
-
226
- In version Rails 4.1, multi_json has been removed, and this patch is unnecessary and will no longer work.
227
- Instead, use the `oj_mimic_json` [gem](https://github.com/ohler55/oj_mimic_json) along with `oj` in your `Gemfile` to have Oj mimic the JSON gem and be used in its place by `ActiveSupport` JSON handling:
228
-
229
- ```
230
- gem 'oj'
231
- gem 'oj_mimic_json'
232
- ```
233
-
234
- ## Security and Optimization
235
-
236
- Two settings in Oj are useful for parsing but do expose a vulnerability if used
237
- from an untrusted source. Symbolized keys can cause memory to be filled with
238
- previous versions of ruby. Ruby 2.1 and below does not garbage collect
239
- Symbols. The same is true for auto defining classes in all versions of ruby;
240
- memory will also be exhausted if too many classes are automatically
241
- defined. Auto defining is a useful feature during development and from trusted
242
- sources but it allows too many classes to be created in the object load mode and
243
- auto defined is used with an untrusted source. The `Oj.strict_load()` method
244
- sets and uses the most strict and safest options. It should be used by
245
- developers who find it difficult to understand the options available in Oj.
246
-
247
- The options in Oj are designed to provide flexibility to the developer. This
248
- flexibility allows Objects to be serialized and deserialized. No methods are
249
- ever called on these created Objects but that does not stop the developer from
250
- calling methods on them. As in any system, check your inputs before working with
251
- them. Taking an arbitrary `String` from a user and evaluating it is never a good
252
- idea from an unsecure source. The same is true for `Object` attributes as they
253
- are not more than `String`s. Always check inputs from untrusted sources.
76
+ See [{file:CHANGELOG.md}](CHANGELOG.md) and [{file:RELEASE_NOTES.md}](RELEASE_NOTES.md)
254
77
 
255
78
  ## Links
256
79
 
257
- *Documentation*: http://www.ohler.com/oj, http://rubydoc.info/gems/oj
80
+ - *Documentation*: http://www.ohler.com/oj/doc, http://rubydoc.info/gems/oj
258
81
 
259
- *GitHub* *repo*: https://github.com/ohler55/oj
82
+ - *GitHub* *repo*: https://github.com/ohler55/oj
260
83
 
261
- *RubyGems* *repo*: https://rubygems.org/gems/oj
84
+ - *RubyGems* *repo*: https://rubygems.org/gems/oj
262
85
 
263
- Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announcements and news about the Oj gem.
86
+ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements and news about the Oj gem.
264
87
 
265
88
  #### Performance Comparisons
266
89
 
267
- [Oj Strict Mode Performance](http://www.ohler.com/dev/oj_misc/performance_strict.html) compares Oj strict mode parser performance to other JSON parsers.
90
+ - [Oj Strict Mode Performance](http://www.ohler.com/dev/oj_misc/performance_strict.html) compares Oj strict mode parser performance to other JSON parsers.
268
91
 
269
- [Oj Compat Mode Performance](http://www.ohler.com/dev/oj_misc/performance_compat.html) compares Oj compat mode parser performance to other JSON parsers.
92
+ - [Oj Compat Mode Performance](http://www.ohler.com/dev/oj_misc/performance_compat.html) compares Oj compat mode parser performance to other JSON parsers.
270
93
 
271
- [Oj Object Mode Performance](http://www.ohler.com/dev/oj_misc/performance_object.html) compares Oj object mode parser performance to other marshallers.
94
+ - [Oj Object Mode Performance](http://www.ohler.com/dev/oj_misc/performance_object.html) compares Oj object mode parser performance to other marshallers.
272
95
 
273
- [Oj Callback Performance](http://www.ohler.com/dev/oj_misc/performance_callback.html) compares Oj callback parser performance to other JSON parsers.
96
+ - [Oj Callback Performance](http://www.ohler.com/dev/oj_misc/performance_callback.html) compares Oj callback parser performance to other JSON parsers.
274
97
 
275
98
  #### Links of Interest
276
99
 
277
- *Fast XML parser and marshaller on RubyGems*: https://rubygems.org/gems/ox
100
+ - *Fast XML parser and marshaller on RubyGems*: https://rubygems.org/gems/ox
101
+
102
+ - *Fast XML parser and marshaller on GitHub*: https://github.com/ohler55/ox
103
+
104
+ - [Need for Speed](http://www.ohler.com/dev/need_for_speed/need_for_speed.html) for an overview of how Oj::Doc was designed.
105
+
106
+ - *OjC, a C JSON parser*: https://www.ohler.com/ojc also at https://github.com/ohler55/ojc
278
107
 
279
- *Fast XML parser and marshaller on GitHub*: https://github.com/ohler55/ox
108
+ - *Agoo, a high performance Ruby web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo
280
109
 
281
- [Oj Object Encoding Format](http://www.ohler.com/dev/oj_misc/encoding_format.html) describes the OJ Object JSON encoding format.
110
+ - *Agoo-C, a high performance C web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo-c
282
111
 
283
- [Need for Speed](http://www.ohler.com/dev/need_for_speed/need_for_speed.html) for an overview of how Oj::Doc was designed.
112
+ - *oj-introspect, an example of creating an Oj parser extension in C*: https://github.com/meinac/oj-introspect
284
113
 
285
- *OjC, a C JSON parser*: https://www.ohler.com/ojc also at https://github.com/ohler55/ojc
114
+ #### Contributing
286
115
 
287
- *Piper Push Cache, push JSON to browsers*: http://www.piperpushcache.com
116
+ + Provide a Pull Request off the `develop` branch.
117
+ + Report a bug
118
+ + Suggest an idea
119
+ + Code is now formatted with the clang-format tool with the configuration file in the root of the repo.
data/RELEASE_NOTES.md ADDED
@@ -0,0 +1,61 @@
1
+ # RELEASE NOTES
2
+
3
+ The release notes here are organized by release. For a list of changes
4
+ see the See [{file:CHANGELOG.md}](CHANGELOG.md) file. In this file are
5
+ the steps to take to aid in keeping things rolling after updating to
6
+ the latest version.
7
+
8
+ ## 3.13.7
9
+
10
+ The default for JSON when mimicked by Oj is now to set
11
+ `:allow_invalid_unicode`. To change that behavior JSON.load, set that
12
+ option to false.
13
+
14
+ ## 3.13.x
15
+
16
+ This release included a new cache that performs better than the
17
+ earlier cache and a new high performance parser.
18
+
19
+ ### Cache
20
+
21
+ The new cache includes a least recently used expiration to reduce
22
+ memory use. The cache is also self adjusting and will expand as needed
23
+ for better performance. It also handles Hash keys and string values
24
+ with two options, `:cache_keys`, a boolean and `:cache_str` an
25
+ integer. The `:cache_str` if set to more than zero is the limit for
26
+ the length of string values to cache. The maximum value is 35 which
27
+ allows strings up to 34 bytes to be cached.
28
+
29
+ One interesting aspect of the cache is not so much the string caching
30
+ which performs similar to the Ruby intern functions but the caching of
31
+ symbols and object attribute names. There is a significant gain for
32
+ symbols and object attributes.
33
+
34
+ If the cache is not desired then setting the default options to turn
35
+ it off can be done with this line:
36
+
37
+ ``` ruby
38
+ Oj.default_options = { cache_keys: false, cache_str: 0 }
39
+ ```
40
+
41
+ ### Oj::Parser
42
+
43
+ The new parser uses a different core that follows the approach taken
44
+ by [OjC](https://github.com/ohler55/ojc) and
45
+ [OjG](https://github.com/ohler55/ojg). It also takes advantage of the
46
+ bulk Array and Hash functions. Another issue the new parser addresses
47
+ is option management. Instead of a single global default_options each
48
+ parser instance maintains it's own options.
49
+
50
+ There is a price to be paid when using the Oj::Parser. The API is not
51
+ the same the older parser. A single parser can only be used in a
52
+ single thread. This allows reuse of internal buffers for additional
53
+ improvements in performance.
54
+
55
+ The performane advantage of the Oj::Parse is that it is more than 3
56
+ times faster than the Oj::compat_load call and 6 times faster than the
57
+ JSON gem.
58
+
59
+ ### Dump Performance
60
+
61
+ Thanks to Watson1978 Oj.dump also received a speed boost.
data/ext/oj/buf.h CHANGED
@@ -1,103 +1,85 @@
1
- /* buf.h
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
- */
1
+ // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
30
3
 
31
- #ifndef __OJ_BUF_H__
32
- #define __OJ_BUF_H__
4
+ #ifndef OJ_BUF_H
5
+ #define OJ_BUF_H
33
6
 
7
+ #include "mem.h"
34
8
  #include "ruby.h"
35
9
 
36
- typedef struct _Buf {
37
- char *head;
38
- char *end;
39
- char *tail;
40
- char base[1024];
10
+ typedef struct _buf {
11
+ char *head;
12
+ char *end;
13
+ char *tail;
14
+ char base[1024];
41
15
  } *Buf;
42
16
 
43
- inline static void
44
- buf_init(Buf buf) {
17
+ inline static void buf_init(Buf buf) {
45
18
  buf->head = buf->base;
46
- buf->end = buf->base + sizeof(buf->base) - 1;
19
+ buf->end = buf->base + sizeof(buf->base) - 1;
47
20
  buf->tail = buf->head;
48
21
  }
49
22
 
50
- inline static void
51
- buf_cleanup(Buf buf) {
23
+ inline static void buf_reset(Buf buf) {
24
+ buf->tail = buf->head;
25
+ }
26
+
27
+ inline static void buf_cleanup(Buf buf) {
52
28
  if (buf->base != buf->head) {
53
- xfree(buf->head);
29
+ OJ_R_FREE(buf->head);
54
30
  }
55
31
  }
56
32
 
57
- inline static size_t
58
- buf_len(Buf buf) {
33
+ inline static size_t buf_len(Buf buf) {
59
34
  return buf->tail - buf->head;
60
35
  }
61
36
 
62
- inline static void
63
- buf_append_string(Buf buf, const char *s, size_t slen) {
37
+ inline static const char *buf_str(Buf buf) {
38
+ *buf->tail = '\0';
39
+ return buf->head;
40
+ }
41
+
42
+ inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
43
+ if (0 == slen) {
44
+ return;
45
+ }
46
+
64
47
  if (buf->end <= buf->tail + slen) {
65
- size_t len = buf->end - buf->head;
66
- size_t toff = buf->tail - buf->head;
67
- size_t new_len = len + slen + len / 2;
48
+ size_t len = buf->end - buf->head;
49
+ size_t toff = buf->tail - buf->head;
50
+ size_t new_len = len + slen + len / 2;
68
51
 
69
- if (buf->base == buf->head) {
70
- buf->head = ALLOC_N(char, new_len);
71
- memcpy(buf->head, buf->base, len);
72
- } else {
73
- REALLOC_N(buf->head, char, new_len);
74
- }
75
- buf->tail = buf->head + toff;
76
- buf->end = buf->head + new_len - 1;
52
+ if (buf->base == buf->head) {
53
+ buf->head = OJ_R_ALLOC_N(char, new_len);
54
+ memcpy(buf->head, buf->base, len);
55
+ } else {
56
+ OJ_R_REALLOC_N(buf->head, char, new_len);
57
+ }
58
+ buf->tail = buf->head + toff;
59
+ buf->end = buf->head + new_len - 1;
77
60
  }
78
61
  memcpy(buf->tail, s, slen);
79
62
  buf->tail += slen;
80
63
  }
81
-
82
- inline static void
83
- buf_append(Buf buf, char c) {
64
+
65
+ inline static void buf_append(Buf buf, char c) {
84
66
  if (buf->end <= buf->tail) {
85
- size_t len = buf->end - buf->head;
86
- size_t toff = buf->tail - buf->head;
87
- size_t new_len = len + len / 2;
67
+ size_t len = buf->end - buf->head;
68
+ size_t toff = buf->tail - buf->head;
69
+ size_t new_len = len + len / 2;
88
70
 
89
- if (buf->base == buf->head) {
90
- buf->head = ALLOC_N(char, new_len);
91
- memcpy(buf->head, buf->base, len);
92
- } else {
93
- REALLOC_N(buf->head, char, new_len);
94
- }
95
- buf->tail = buf->head + toff;
96
- buf->end = buf->head + new_len - 1;
71
+ if (buf->base == buf->head) {
72
+ buf->head = OJ_R_ALLOC_N(char, new_len);
73
+ memcpy(buf->head, buf->base, len);
74
+ } else {
75
+ OJ_R_REALLOC_N(buf->head, char, new_len);
76
+ }
77
+ buf->tail = buf->head + toff;
78
+ buf->end = buf->head + new_len - 1;
97
79
  }
98
80
  *buf->tail = c;
99
81
  buf->tail++;
100
82
  //*buf->tail = '\0'; // for debugging
101
83
  }
102
84
 
103
- #endif /* __OJ_BUF_H__ */
85
+ #endif /* OJ_BUF_H */