json 2.7.1 → 2.7.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d39ddfc605399a55f202bd106776ede02812c232d813469165dfd9c06dbea5d
4
- data.tar.gz: d168c4f8aa5fe5f13e570e454c997fb91f6946ce8b339b0ef3477486edd8e99d
3
+ metadata.gz: 5be5bacbb4459129b1e489146ef79efa7b23c48ebaf1f41e53709625f7cef0c7
4
+ data.tar.gz: 4d8080d605d1dd3750f2a95d2f17fedc0262ffe73438690f6f1b6e66d3511cf9
5
5
  SHA512:
6
- metadata.gz: 3511a0cfd5365e476b39181201b0cd4ea8d415774ca524958955647bbeb9db0ddf5bbafae8f816fbb5b0459d643aa6345c63d5f3ec9443cd67c15cea50c0db57
7
- data.tar.gz: f015ec65ce58d4d946626162d29af7e24d26689fde3162b07b7a7b45d2f90049d676d8d1c22127ae1b7a6fdfb1926a80cb865330b9da458b700682d7d626b1b0
6
+ metadata.gz: c30ac0e64c2ec2d2a677aba6c5eb50618bd7e33873a8b367339f2f25d2e76875cc8d01651e8f6df6a9b0814a75df8021b68b6fe181a34c46737ddc887f8e3c8f
7
+ data.tar.gz: 83b459d7b7c20602c772dbb323159fccde46eff4ef43d6773614941ee0e4eee8bdb39926702ce91f523821ce1e9a4efa49c4e63121d503e20a59788588dfc8a6
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/CHANGES.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changes
2
2
 
3
+ * Numerous performance optimizations in `JSON.generate` and `JSON.dump`.
4
+ * Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
5
+ * Fix json-pure's `Object#to_json` to accept non state arguments
6
+ * Fix multiline comment support in `json-pure`.
7
+ * Fix `JSON.parse` to no longer mutate the argument encoding when passed an ASCII-8BIT string.
8
+ * Fix `String#to_json` to raise on invalid encoding in `json-pure`.
9
+ * Delete code that was based on CVTUTF.
10
+ * Use the pure-Ruby generator on TruffleRuby.
11
+ * Fix `strict` mode in `json-pure` to not break on Integer.
12
+
13
+ ### 2024-04-04 (2.7.2)
14
+
15
+ * Use rb_sym2str instead of SYM2ID #561
16
+ * Fix memory leak when exception is raised during JSON generation #574
17
+ * Remove references to "19" methods in JRuby #576
18
+ * Make OpenStruct support as optional by @hsbt in #565
19
+ * Autoload JSON::GenericObject to avoid require ostruct warning in Ruby 3.4 #577
20
+ * Warn to install ostruct if json couldn't load it by @hsbt #578
21
+
3
22
  ### 2023-12-05 (2.7.1)
4
23
 
5
24
  * JSON.dump: handle unenclosed hashes regression #554
@@ -168,7 +187,7 @@
168
187
  * Remove Rubinius exception since transcoding should be working now.
169
188
 
170
189
  ## 2013-05-13 (1.8.0)
171
- * Fix https://github.com/flori/json/issues/162 reported by Marc-Andre
190
+ * Fix https://github.com/ruby/json/issues/162 reported by Marc-Andre
172
191
  Lafortune <github_rocks@marc-andre.ca>. Thanks!
173
192
  * Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with
174
193
  -Wchar-subscripts and better validate UTF-8 strings.
@@ -188,7 +207,7 @@
188
207
  JSON::GenericObject.json_creatable = true
189
208
  as well.
190
209
  * Remove useless assert in fbuffer implementation.
191
- * Apply patch attached to https://github.com/flori/json/issues#issue/155
210
+ * Apply patch attached to https://github.com/ruby/json/issues#issue/155
192
211
  provided by John Shahid <jvshahid@gmail.com>, Thx!
193
212
  * Add license information to rubygems spec data, reported by Jordi Massaguer Pla <jmassaguerpla@suse.de>.
194
213
  * Improve documentation, thx to Zachary Scott <zachary@zacharyscott.net>.
@@ -202,7 +221,7 @@
202
221
  * Fix compilation of extension on older rubies.
203
222
 
204
223
  ## 2012-07-26 (1.7.4)
205
- * Fix compilation problem on AIX, see https://github.com/flori/json/issues/142
224
+ * Fix compilation problem on AIX, see https://github.com/ruby/json/issues/142
206
225
 
207
226
  ## 2012-05-12 (1.7.3)
208
227
  * Work around Rubinius encoding issues using iconv for conversion instead.
@@ -224,9 +243,9 @@
224
243
  * Propagate src encoding to values made from it (fixes 1.9 mode converting
225
244
  everything to ascii-8bit; harmless for 1.8 mode too) (Thomas E. Enebo
226
245
  <tom.enebo@gmail.com>), should fix
227
- https://github.com/flori/json/issues#issue/119.
228
- * Fix https://github.com/flori/json/issues#issue/124 Thx to Jason Hutchens.
229
- * Fix https://github.com/flori/json/issues#issue/117
246
+ https://github.com/ruby/json/issues#issue/119.
247
+ * Fix https://github.com/ruby/json/issues#issue/124 Thx to Jason Hutchens.
248
+ * Fix https://github.com/ruby/json/issues#issue/117
230
249
 
231
250
  ## 2012-01-15 (1.6.5)
232
251
  * Vit Ondruch <v.ondruch@tiscali.cz> reported a bug that shows up when using
@@ -253,7 +272,7 @@
253
272
  patch go to Josh Partlow (jpartlow@github).
254
273
  * Improve parsing speed for JSON numbers (integers and floats) in a similar way to
255
274
  what Evan Phoenix <evan@phx.io> suggested in:
256
- https://github.com/flori/json/pull/103
275
+ https://github.com/ruby/json/pull/103
257
276
 
258
277
  ## 2011-09-18 (1.6.1)
259
278
  * Using -target 1.5 to force Java bits to compile with 1.5.
@@ -266,15 +285,14 @@
266
285
  * Fix memory leak when used from multiple JRuby. (Patch by
267
286
  jfirebaugh@github).
268
287
  * Apply patch by Eric Wong <nocode@yhbt.net> that fixes garbage collection problem
269
- reported in https://github.com/flori/json/issues/46.
288
+ reported in https://github.com/ruby/json/issues/46.
270
289
  * Add :quirks_mode option to parser and generator.
271
290
  * Add support for Rational and Complex number additions via json/add/complex
272
291
  and json/add/rational requires.
273
292
 
274
293
  ## 2011-06-20 (1.5.3)
275
294
  * Alias State#configure method as State#merge to increase duck type synonymy with Hash.
276
- * Add `as_json` methods in json/add/core, so rails can create its json objects
277
- the new way.
295
+ * Add `as_json` methods in json/add/core, so rails can create its json objects the new way.
278
296
 
279
297
  ## 2011-05-11 (1.5.2)
280
298
  * Apply documentation patch by Cory Monty <cory.monty@gmail.com>.
@@ -285,7 +303,7 @@
285
303
 
286
304
  ## 2011-01-24 (1.5.1)
287
305
  * Made rake-compiler build a fat binary gem. This should fix issue
288
- https://github.com/flori/json/issues#issue/54.
306
+ https://github.com/ruby/json/issues#issue/54.
289
307
 
290
308
  ## 2011-01-22 (1.5.0)
291
309
  * Included Java source codes for the Jruby extension made by Daniel Luz
@@ -295,7 +313,7 @@
295
313
  reported by Riley Goodside.
296
314
 
297
315
  ## 2010-08-09 (1.4.6)
298
- * Fixed oversight reported in http://github.com/flori/json/issues/closed#issue/23,
316
+ * Fixed oversight reported in http://github.com/ruby/json/issues/closed#issue/23,
299
317
  always create a new object from the state prototype.
300
318
  * Made pure and ext api more similar again.
301
319
 
@@ -305,12 +323,12 @@
305
323
  argument.
306
324
  * Some fixes in the state objects and additional tests.
307
325
  ## 2010-08-06 (1.4.4)
308
- * Fixes build problem for rubinius under OS X, http://github.com/flori/json/issues/closed#issue/25
309
- * Fixes crashes described in http://github.com/flori/json/issues/closed#issue/21 and
310
- http://github.com/flori/json/issues/closed#issue/23
326
+ * Fixes build problem for rubinius under OS X, http://github.com/ruby/json/issues/closed#issue/25
327
+ * Fixes crashes described in http://github.com/ruby/json/issues/closed#issue/21 and
328
+ http://github.com/ruby/json/issues/closed#issue/23
311
329
  ## 2010-05-05 (1.4.3)
312
330
  * Fixed some test assertions, from Ruby r27587 and r27590, patch by nobu.
313
- * Fixed issue http://github.com/flori/json/issues/#issue/20 reported by
331
+ * Fixed issue http://github.com/ruby/json/issues/#issue/20 reported by
314
332
  electronicwhisper@github. Thx!
315
333
 
316
334
  ## 2010-04-26 (1.4.2)
@@ -332,7 +350,7 @@
332
350
  * Extension should at least be compatible with MRI, YARV and Rubinius.
333
351
 
334
352
  ## 2010-04-07 (1.2.4)
335
- * Triger const_missing callback to make Rails' dynamic class loading work.
353
+ * Trigger const_missing callback to make Rails' dynamic class loading work.
336
354
 
337
355
  ## 2010-03-11 (1.2.3)
338
356
  * Added a `State#[]` method which returns an attribute's value in order to
data/LEGAL ADDED
@@ -0,0 +1,60 @@
1
+ # -*- rdoc -*-
2
+
3
+ = LEGAL NOTICE INFORMATION
4
+ --------------------------
5
+
6
+ All the files in this distribution are covered under either the Ruby's
7
+ license (see the file COPYING) or public-domain except some files
8
+ mentioned below.
9
+
10
+ == MIT License
11
+ >>>
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ "Software"), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, and/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ == Old-style BSD license
32
+ >>>
33
+ Redistribution and use in source and binary forms, with or without
34
+ modification, are permitted provided that the following conditions
35
+ are met:
36
+ 1. Redistributions of source code must retain the above copyright
37
+ notice, this list of conditions and the following disclaimer.
38
+ 2. Redistributions in binary form must reproduce the above copyright
39
+ notice, this list of conditions and the following disclaimer in the
40
+ documentation and/or other materials provided with the distribution.
41
+ 3. Neither the name of the University nor the names of its contributors
42
+ may be used to endorse or promote products derived from this software
43
+ without specific prior written permission.
44
+
45
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55
+ SUCH DAMAGE.
56
+
57
+ IMPORTANT NOTE::
58
+
59
+ From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
60
+ paragraph 3 above is now null and void.
data/README.md CHANGED
@@ -1,18 +1,17 @@
1
1
  # JSON implementation for Ruby
2
2
 
3
- [![CI](https://github.com/flori/json/actions/workflows/ci.yml/badge.svg)](https://github.com/flori/json/actions/workflows/ci.yml)
3
+ [![CI](https://github.com/ruby/json/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/json/actions/workflows/ci.yml)
4
4
 
5
5
  ## Description
6
6
 
7
- This is a implementation of the JSON specification according to RFC 7159
8
- http://www.ietf.org/rfc/rfc7159.txt . Starting from version 1.0.0 on there
9
- will be two variants available:
7
+ This is an implementation of the JSON specification according to RFC 7159
8
+ http://www.ietf.org/rfc/rfc7159.txt . There is two variants available:
10
9
 
11
- * A pure ruby variant, that relies on the iconv and the stringscan
12
- extensions, which are both part of the ruby standard library.
10
+ * A pure ruby variant, that relies on the `strscan` extensions, which is
11
+ part of the ruby standard library.
13
12
  * The quite a bit faster native extension variant, which is in parts
14
- implemented in C or Java and comes with its own unicode conversion
15
- functions and a parser generated by the [Ragel] state machine compiler.
13
+ implemented in C or Java and comes with a parser generated by the [Ragel]
14
+ state machine compiler.
16
15
 
17
16
  Both variants of the JSON generator generate UTF-8 character sequences by
18
17
  default. If an :ascii\_only option with a true value is given, they escape all
@@ -32,45 +31,19 @@ It's recommended to use the extension variant of JSON, because it's faster than
32
31
  the pure ruby variant. If you cannot build it on your system, you can settle
33
32
  for the latter.
34
33
 
35
- Just type into the command line as root:
34
+ Install the gem and add to the application's Gemfile by executing:
36
35
 
37
- ```
38
- # rake install
39
- ```
40
-
41
- The above command will build the extensions and install them on your system.
42
-
43
- ```
44
- # rake install_pure
45
- ```
46
-
47
- or
48
-
49
- ```
50
- # ruby install.rb
51
- ```
36
+ $ bundle add json
52
37
 
53
- will just install the pure ruby implementation of JSON.
38
+ If bundler is not being used to manage dependencies, install the gem by executing:
54
39
 
55
- If you use Rubygems you can type
40
+ $ gem install json
56
41
 
57
- ```
58
- # gem install json
59
- ```
60
-
61
- instead, to install the newest JSON version.
62
42
 
63
43
  There is also a pure ruby json only variant of the gem, that can be installed
64
44
  with:
65
45
 
66
- ```
67
- # gem install json_pure
68
- ```
69
-
70
- ## Compiling the extensions yourself
71
-
72
- If you want to create the `parser.c` file from its `parser.rl` file or draw nice
73
- graphviz images of the state machines, you need [Ragel].
46
+ $ gem install json_pure
74
47
 
75
48
  ## Usage
76
49
 
@@ -140,15 +113,6 @@ JSON JSON(1..10) # => 1..10
140
113
  To find out how to add JSON support to other or your own classes, read the
141
114
  section "More Examples" below.
142
115
 
143
- To get the best compatibility to rails' JSON implementation, you can
144
-
145
- ```ruby
146
- require 'json/add/rails'
147
- ```
148
-
149
- Both of the additions attempt to require `'json'` (like above) first, if it has
150
- not been required yet.
151
-
152
116
  ## Serializing exceptions
153
117
 
154
118
  The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
@@ -263,136 +227,11 @@ There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
263
227
  `pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
264
228
  the `pp` library's `pp` methods.
265
229
 
266
- The script `tools/server.rb` contains a small example if you want to test, how
267
- receiving a JSON object from a webrick server in your browser with the
268
- JavaScript prototype library http://www.prototypejs.org works.
269
-
270
- ## Speed Comparisons
271
-
272
- I have created some benchmark results (see the benchmarks/data-p4-3Ghz
273
- subdir of the package) for the JSON-parser to estimate the speed up in the C
274
- extension:
275
-
276
- ```
277
- Comparing times (call_time_mean):
278
- 1 ParserBenchmarkExt#parser 900 repeats:
279
- 553.922304770 ( real) -> 21.500x
280
- 0.001805307
281
- 2 ParserBenchmarkYAML#parser 1000 repeats:
282
- 224.513358139 ( real) -> 8.714x
283
- 0.004454078
284
- 3 ParserBenchmarkPure#parser 1000 repeats:
285
- 26.755020642 ( real) -> 1.038x
286
- 0.037376163
287
- 4 ParserBenchmarkRails#parser 1000 repeats:
288
- 25.763381731 ( real) -> 1.000x
289
- 0.038814780
290
- calls/sec ( time) -> speed covers
291
- secs/call
292
- ```
293
-
294
- In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
295
- compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
296
- `ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
297
- input first to YAML and then uses the YAML-parser, the conversion seems to
298
- slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
299
-
300
- If you look at the benchmark data you can see that this is mostly caused by
301
- the frequent high outliers - the median of the Rails-parser runs is still
302
- overall smaller than the median of the `JSON::Pure::Parser` runs:
303
-
304
- ```
305
- Comparing times (call_time_median):
306
- 1 ParserBenchmarkExt#parser 900 repeats:
307
- 800.592479481 ( real) -> 26.936x
308
- 0.001249075
309
- 2 ParserBenchmarkYAML#parser 1000 repeats:
310
- 271.002390644 ( real) -> 9.118x
311
- 0.003690004
312
- 3 ParserBenchmarkRails#parser 1000 repeats:
313
- 30.227910865 ( real) -> 1.017x
314
- 0.033082008
315
- 4 ParserBenchmarkPure#parser 1000 repeats:
316
- 29.722384421 ( real) -> 1.000x
317
- 0.033644676
318
- calls/sec ( time) -> speed covers
319
- secs/call
320
- ```
321
-
322
- I have benchmarked the `JSON-Generator` as well. This generated a few more
323
- values, because there are different modes that also influence the achieved
324
- speed:
325
-
326
- ```
327
- Comparing times (call_time_mean):
328
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
329
- 547.354332608 ( real) -> 15.090x
330
- 0.001826970
331
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
332
- 443.968212317 ( real) -> 12.240x
333
- 0.002252414
334
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
335
- 375.104545883 ( real) -> 10.341x
336
- 0.002665923
337
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
338
- 49.978706968 ( real) -> 1.378x
339
- 0.020008521
340
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
341
- 38.531868759 ( real) -> 1.062x
342
- 0.025952543
343
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
344
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
345
- 0.027079979
346
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
347
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
348
- 0.027569373
349
- calls/sec ( time) -> speed covers
350
- secs/call
351
- ```
352
-
353
- In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
354
- `JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
355
- bit faster than the `generator_safe` and `generator_pretty` methods of the pure
356
- variant but slower than the others.
357
-
358
- To achieve the fastest JSON document output, you can use the `fast_generate`
359
- method. Beware, that this will disable the checking for circular Ruby data
360
- structures, which may cause JSON to go into an infinite loop.
361
-
362
- Here are the median comparisons for completeness' sake:
363
-
364
- ```
365
- Comparing times (call_time_median):
366
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
367
- 708.258020939 ( real) -> 16.547x
368
- 0.001411915
369
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
370
- 569.105020353 ( real) -> 13.296x
371
- 0.001757145
372
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
373
- 482.825371244 ( real) -> 11.280x
374
- 0.002071142
375
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
376
- 62.717626652 ( real) -> 1.465x
377
- 0.015944481
378
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
379
- 43.965681162 ( real) -> 1.027x
380
- 0.022745013
381
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
382
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
383
- 0.022763968
384
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
385
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
386
- 0.023363113
387
- calls/sec ( time) -> speed covers
388
- secs/call
389
- ```
390
-
391
230
  ## Development
392
231
 
393
232
  ### Release
394
233
 
395
- Update the json.gemspec and json-java.gemspec.
234
+ Update the `lib/json/version.rb` file.
396
235
 
397
236
  ```
398
237
  rbenv shell 2.6.5
@@ -1,47 +1,8 @@
1
-
2
1
  #ifndef _FBUFFER_H_
3
2
  #define _FBUFFER_H_
4
3
 
5
4
  #include "ruby.h"
6
-
7
- #ifndef RHASH_SIZE
8
- #define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
9
- #endif
10
-
11
- #ifndef RFLOAT_VALUE
12
- #define RFLOAT_VALUE(val) (RFLOAT(val)->value)
13
- #endif
14
-
15
- #ifndef RARRAY_LEN
16
- #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
17
- #endif
18
- #ifndef RSTRING_PTR
19
- #define RSTRING_PTR(string) RSTRING(string)->ptr
20
- #endif
21
- #ifndef RSTRING_LEN
22
- #define RSTRING_LEN(string) RSTRING(string)->len
23
- #endif
24
-
25
- #ifdef PRIsVALUE
26
- # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
27
- # define RB_OBJ_STRING(obj) (obj)
28
- #else
29
- # define PRIsVALUE "s"
30
- # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
31
- # define RB_OBJ_STRING(obj) StringValueCStr(obj)
32
- #endif
33
-
34
- #ifdef HAVE_RUBY_ENCODING_H
35
5
  #include "ruby/encoding.h"
36
- #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
37
- #else
38
- #define FORCE_UTF8(obj)
39
- #endif
40
-
41
- /* We don't need to guard objects for rbx, so let's do nothing at all. */
42
- #ifndef RB_GC_GUARD
43
- #define RB_GC_GUARD(object)
44
- #endif
45
6
 
46
7
  typedef struct FBufferStruct {
47
8
  unsigned long initial_length;
@@ -59,17 +20,22 @@ typedef struct FBufferStruct {
59
20
 
60
21
  static FBuffer *fbuffer_alloc(unsigned long initial_length);
61
22
  static void fbuffer_free(FBuffer *fb);
23
+ #ifndef JSON_GENERATOR
62
24
  static void fbuffer_clear(FBuffer *fb);
25
+ #endif
63
26
  static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len);
64
27
  #ifdef JSON_GENERATOR
65
28
  static void fbuffer_append_long(FBuffer *fb, long number);
66
29
  #endif
67
30
  static void fbuffer_append_char(FBuffer *fb, char newchr);
68
31
  #ifdef JSON_GENERATOR
69
- static FBuffer *fbuffer_dup(FBuffer *fb);
70
32
  static VALUE fbuffer_to_s(FBuffer *fb);
71
33
  #endif
72
34
 
35
+ #ifndef RB_UNLIKELY
36
+ #define RB_UNLIKELY(expr) expr
37
+ #endif
38
+
73
39
  static FBuffer *fbuffer_alloc(unsigned long initial_length)
74
40
  {
75
41
  FBuffer *fb;
@@ -86,25 +52,29 @@ static void fbuffer_free(FBuffer *fb)
86
52
  ruby_xfree(fb);
87
53
  }
88
54
 
55
+ #ifndef JSON_GENERATOR
89
56
  static void fbuffer_clear(FBuffer *fb)
90
57
  {
91
58
  fb->len = 0;
92
59
  }
60
+ #endif
93
61
 
94
- static void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
62
+ static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
95
63
  {
96
- unsigned long required;
64
+ if (RB_UNLIKELY(requested > fb->capa - fb->len)) {
65
+ unsigned long required;
97
66
 
98
- if (!fb->ptr) {
99
- fb->ptr = ALLOC_N(char, fb->initial_length);
100
- fb->capa = fb->initial_length;
101
- }
67
+ if (RB_UNLIKELY(!fb->ptr)) {
68
+ fb->ptr = ALLOC_N(char, fb->initial_length);
69
+ fb->capa = fb->initial_length;
70
+ }
102
71
 
103
- for (required = fb->capa; requested > required - fb->len; required <<= 1);
72
+ for (required = fb->capa; requested > required - fb->len; required <<= 1);
104
73
 
105
- if (required > fb->capa) {
106
- REALLOC_N(fb->ptr, char, required);
107
- fb->capa = required;
74
+ if (required > fb->capa) {
75
+ REALLOC_N(fb->ptr, char, required);
76
+ fb->capa = required;
77
+ }
108
78
  }
109
79
  }
110
80
 
@@ -166,21 +136,10 @@ static void fbuffer_append_long(FBuffer *fb, long number)
166
136
  fbuffer_append(fb, buf, len);
167
137
  }
168
138
 
169
- static FBuffer *fbuffer_dup(FBuffer *fb)
170
- {
171
- unsigned long len = fb->len;
172
- FBuffer *result;
173
-
174
- result = fbuffer_alloc(len);
175
- fbuffer_append(result, FBUFFER_PAIR(fb));
176
- return result;
177
- }
178
-
179
139
  static VALUE fbuffer_to_s(FBuffer *fb)
180
140
  {
181
- VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
141
+ VALUE result = rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
182
142
  fbuffer_free(fb);
183
- FORCE_UTF8(result);
184
143
  return result;
185
144
  }
186
145
  #endif
@@ -1,4 +1,10 @@
1
1
  require 'mkmf'
2
2
 
3
- $defs << "-DJSON_GENERATOR"
4
- create_makefile 'json/ext/generator'
3
+ if RUBY_ENGINE == 'truffleruby'
4
+ # The pure-Ruby generator is faster on TruffleRuby, so skip compiling the generator extension
5
+ File.write('Makefile', dummy_makefile("").join)
6
+ else
7
+ append_cflags("-std=c99")
8
+ $defs << "-DJSON_GENERATOR"
9
+ create_makefile 'json/ext/generator'
10
+ end