json 2.7.2 → 2.7.3

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: 1ae811d90e98bbf8438c5abff24a9eabd5ef9c929115c14d3616a0c23f3a3fa2
4
- data.tar.gz: eaa6afeb5ed814f5272bf54172b98ab217b26f850cb91d6fb081a9551237030c
3
+ metadata.gz: 1500b32611dd205778d21f8175a6e587c85d8090e9861c6ab5c2bbdc8cc7b107
4
+ data.tar.gz: 7bccf2b0c350f282b152f0e85addedb62d596c83a5347afa4205bb025f1dd24f
5
5
  SHA512:
6
- metadata.gz: c4119c5fdb66b553ee50cab0185cdec0ff7b09f102cfec8faa28efe2a6042d1e5cb46ada853afdc47b76707b5b180e0f68fb039e08e329935434716e2419b8e1
7
- data.tar.gz: f7d69e1e729e4b37687358bd6ebf81e8909fe4418bfff5c8a2d676b070d6af979146d0b18c01820d5bd4a7f567a62cbb90d0e164e96d05c0e99d9968657467c0
6
+ metadata.gz: cf52a3ae9060dcebbc0febfde70aba86d718dd0545eb55da4f25e7fffa3bacbaff82e56656c189f6d7ffd25093c9a5967085864ce1db921dcb0e9cc92c9b299f
7
+ data.tar.gz: 55d5e7da5ff1dee20b3a48e08d7a8e389fe8cd4a1f6569ca84d0a59f0e84085fb5af3e2a6721f76ea7dfd860bdbdc8844e7464572191be0c816bf0522036edd0
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,26 @@
1
1
  # Changes
2
2
 
3
+ ### 2024-10-24 (2.7.3)
4
+
5
+ * Numerous performance optimizations in `JSON.generate` and `JSON.dump` (up to 2 times faster).
6
+ * Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
7
+ * Fix json-pure's `Object#to_json` to accept non state arguments
8
+ * Fix multiline comment support in `json-pure`.
9
+ * Fix `JSON.parse` to no longer mutate the argument encoding when passed an ASCII-8BIT string.
10
+ * Fix `String#to_json` to raise on invalid encoding in `json-pure`.
11
+ * Delete code that was based on CVTUTF.
12
+ * Use the pure-Ruby generator on TruffleRuby.
13
+ * Fix `strict` mode in `json-pure` to not break on Integer.
14
+
15
+ ### 2024-04-04 (2.7.2)
16
+
17
+ * Use rb_sym2str instead of SYM2ID #561
18
+ * Fix memory leak when exception is raised during JSON generation #574
19
+ * Remove references to "19" methods in JRuby #576
20
+ * Make OpenStruct support as optional by @hsbt in #565
21
+ * Autoload JSON::GenericObject to avoid require ostruct warning in Ruby 3.4 #577
22
+ * Warn to install ostruct if json couldn't load it by @hsbt #578
23
+
3
24
  ### 2023-12-05 (2.7.1)
4
25
 
5
26
  * JSON.dump: handle unenclosed hashes regression #554
@@ -168,7 +189,7 @@
168
189
  * Remove Rubinius exception since transcoding should be working now.
169
190
 
170
191
  ## 2013-05-13 (1.8.0)
171
- * Fix https://github.com/flori/json/issues/162 reported by Marc-Andre
192
+ * Fix https://github.com/ruby/json/issues/162 reported by Marc-Andre
172
193
  Lafortune <github_rocks@marc-andre.ca>. Thanks!
173
194
  * Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with
174
195
  -Wchar-subscripts and better validate UTF-8 strings.
@@ -188,7 +209,7 @@
188
209
  JSON::GenericObject.json_creatable = true
189
210
  as well.
190
211
  * Remove useless assert in fbuffer implementation.
191
- * Apply patch attached to https://github.com/flori/json/issues#issue/155
212
+ * Apply patch attached to https://github.com/ruby/json/issues#issue/155
192
213
  provided by John Shahid <jvshahid@gmail.com>, Thx!
193
214
  * Add license information to rubygems spec data, reported by Jordi Massaguer Pla <jmassaguerpla@suse.de>.
194
215
  * Improve documentation, thx to Zachary Scott <zachary@zacharyscott.net>.
@@ -202,7 +223,7 @@
202
223
  * Fix compilation of extension on older rubies.
203
224
 
204
225
  ## 2012-07-26 (1.7.4)
205
- * Fix compilation problem on AIX, see https://github.com/flori/json/issues/142
226
+ * Fix compilation problem on AIX, see https://github.com/ruby/json/issues/142
206
227
 
207
228
  ## 2012-05-12 (1.7.3)
208
229
  * Work around Rubinius encoding issues using iconv for conversion instead.
@@ -224,9 +245,9 @@
224
245
  * Propagate src encoding to values made from it (fixes 1.9 mode converting
225
246
  everything to ascii-8bit; harmless for 1.8 mode too) (Thomas E. Enebo
226
247
  <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
248
+ https://github.com/ruby/json/issues#issue/119.
249
+ * Fix https://github.com/ruby/json/issues#issue/124 Thx to Jason Hutchens.
250
+ * Fix https://github.com/ruby/json/issues#issue/117
230
251
 
231
252
  ## 2012-01-15 (1.6.5)
232
253
  * Vit Ondruch <v.ondruch@tiscali.cz> reported a bug that shows up when using
@@ -253,7 +274,7 @@
253
274
  patch go to Josh Partlow (jpartlow@github).
254
275
  * Improve parsing speed for JSON numbers (integers and floats) in a similar way to
255
276
  what Evan Phoenix <evan@phx.io> suggested in:
256
- https://github.com/flori/json/pull/103
277
+ https://github.com/ruby/json/pull/103
257
278
 
258
279
  ## 2011-09-18 (1.6.1)
259
280
  * Using -target 1.5 to force Java bits to compile with 1.5.
@@ -266,15 +287,14 @@
266
287
  * Fix memory leak when used from multiple JRuby. (Patch by
267
288
  jfirebaugh@github).
268
289
  * Apply patch by Eric Wong <nocode@yhbt.net> that fixes garbage collection problem
269
- reported in https://github.com/flori/json/issues/46.
290
+ reported in https://github.com/ruby/json/issues/46.
270
291
  * Add :quirks_mode option to parser and generator.
271
292
  * Add support for Rational and Complex number additions via json/add/complex
272
293
  and json/add/rational requires.
273
294
 
274
295
  ## 2011-06-20 (1.5.3)
275
296
  * 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.
297
+ * Add `as_json` methods in json/add/core, so rails can create its json objects the new way.
278
298
 
279
299
  ## 2011-05-11 (1.5.2)
280
300
  * Apply documentation patch by Cory Monty <cory.monty@gmail.com>.
@@ -285,7 +305,7 @@
285
305
 
286
306
  ## 2011-01-24 (1.5.1)
287
307
  * Made rake-compiler build a fat binary gem. This should fix issue
288
- https://github.com/flori/json/issues#issue/54.
308
+ https://github.com/ruby/json/issues#issue/54.
289
309
 
290
310
  ## 2011-01-22 (1.5.0)
291
311
  * Included Java source codes for the Jruby extension made by Daniel Luz
@@ -295,7 +315,7 @@
295
315
  reported by Riley Goodside.
296
316
 
297
317
  ## 2010-08-09 (1.4.6)
298
- * Fixed oversight reported in http://github.com/flori/json/issues/closed#issue/23,
318
+ * Fixed oversight reported in http://github.com/ruby/json/issues/closed#issue/23,
299
319
  always create a new object from the state prototype.
300
320
  * Made pure and ext api more similar again.
301
321
 
@@ -305,12 +325,12 @@
305
325
  argument.
306
326
  * Some fixes in the state objects and additional tests.
307
327
  ## 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
328
+ * Fixes build problem for rubinius under OS X, http://github.com/ruby/json/issues/closed#issue/25
329
+ * Fixes crashes described in http://github.com/ruby/json/issues/closed#issue/21 and
330
+ http://github.com/ruby/json/issues/closed#issue/23
311
331
  ## 2010-05-05 (1.4.3)
312
332
  * 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
333
+ * Fixed issue http://github.com/ruby/json/issues/#issue/20 reported by
314
334
  electronicwhisper@github. Thx!
315
335
 
316
336
  ## 2010-04-26 (1.4.2)
@@ -332,7 +352,7 @@
332
352
  * Extension should at least be compatible with MRI, YARV and Rubinius.
333
353
 
334
354
  ## 2010-04-07 (1.2.4)
335
- * Triger const_missing callback to make Rails' dynamic class loading work.
355
+ * Trigger const_missing callback to make Rails' dynamic class loading work.
336
356
 
337
357
  ## 2010-03-11 (1.2.3)
338
358
  * 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
 
@@ -254,136 +227,11 @@ There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
254
227
  `pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
255
228
  the `pp` library's `pp` methods.
256
229
 
257
- The script `tools/server.rb` contains a small example if you want to test, how
258
- receiving a JSON object from a webrick server in your browser with the
259
- JavaScript prototype library http://www.prototypejs.org works.
260
-
261
- ## Speed Comparisons
262
-
263
- I have created some benchmark results (see the benchmarks/data-p4-3Ghz
264
- subdir of the package) for the JSON-parser to estimate the speed up in the C
265
- extension:
266
-
267
- ```
268
- Comparing times (call_time_mean):
269
- 1 ParserBenchmarkExt#parser 900 repeats:
270
- 553.922304770 ( real) -> 21.500x
271
- 0.001805307
272
- 2 ParserBenchmarkYAML#parser 1000 repeats:
273
- 224.513358139 ( real) -> 8.714x
274
- 0.004454078
275
- 3 ParserBenchmarkPure#parser 1000 repeats:
276
- 26.755020642 ( real) -> 1.038x
277
- 0.037376163
278
- 4 ParserBenchmarkRails#parser 1000 repeats:
279
- 25.763381731 ( real) -> 1.000x
280
- 0.038814780
281
- calls/sec ( time) -> speed covers
282
- secs/call
283
- ```
284
-
285
- In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
286
- compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
287
- `ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
288
- input first to YAML and then uses the YAML-parser, the conversion seems to
289
- slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
290
-
291
- If you look at the benchmark data you can see that this is mostly caused by
292
- the frequent high outliers - the median of the Rails-parser runs is still
293
- overall smaller than the median of the `JSON::Pure::Parser` runs:
294
-
295
- ```
296
- Comparing times (call_time_median):
297
- 1 ParserBenchmarkExt#parser 900 repeats:
298
- 800.592479481 ( real) -> 26.936x
299
- 0.001249075
300
- 2 ParserBenchmarkYAML#parser 1000 repeats:
301
- 271.002390644 ( real) -> 9.118x
302
- 0.003690004
303
- 3 ParserBenchmarkRails#parser 1000 repeats:
304
- 30.227910865 ( real) -> 1.017x
305
- 0.033082008
306
- 4 ParserBenchmarkPure#parser 1000 repeats:
307
- 29.722384421 ( real) -> 1.000x
308
- 0.033644676
309
- calls/sec ( time) -> speed covers
310
- secs/call
311
- ```
312
-
313
- I have benchmarked the `JSON-Generator` as well. This generated a few more
314
- values, because there are different modes that also influence the achieved
315
- speed:
316
-
317
- ```
318
- Comparing times (call_time_mean):
319
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
320
- 547.354332608 ( real) -> 15.090x
321
- 0.001826970
322
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
323
- 443.968212317 ( real) -> 12.240x
324
- 0.002252414
325
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
326
- 375.104545883 ( real) -> 10.341x
327
- 0.002665923
328
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
329
- 49.978706968 ( real) -> 1.378x
330
- 0.020008521
331
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
332
- 38.531868759 ( real) -> 1.062x
333
- 0.025952543
334
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
335
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
336
- 0.027079979
337
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
338
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
339
- 0.027569373
340
- calls/sec ( time) -> speed covers
341
- secs/call
342
- ```
343
-
344
- In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
345
- `JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
346
- bit faster than the `generator_safe` and `generator_pretty` methods of the pure
347
- variant but slower than the others.
348
-
349
- To achieve the fastest JSON document output, you can use the `fast_generate`
350
- method. Beware, that this will disable the checking for circular Ruby data
351
- structures, which may cause JSON to go into an infinite loop.
352
-
353
- Here are the median comparisons for completeness' sake:
354
-
355
- ```
356
- Comparing times (call_time_median):
357
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
358
- 708.258020939 ( real) -> 16.547x
359
- 0.001411915
360
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
361
- 569.105020353 ( real) -> 13.296x
362
- 0.001757145
363
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
364
- 482.825371244 ( real) -> 11.280x
365
- 0.002071142
366
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
367
- 62.717626652 ( real) -> 1.465x
368
- 0.015944481
369
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
370
- 43.965681162 ( real) -> 1.027x
371
- 0.022745013
372
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
373
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
374
- 0.022763968
375
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
376
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
377
- 0.023363113
378
- calls/sec ( time) -> speed covers
379
- secs/call
380
- ```
381
-
382
230
  ## Development
383
231
 
384
232
  ### Release
385
233
 
386
- Update the json.gemspec and json-java.gemspec.
234
+ Update the `lib/json/version.rb` file.
387
235
 
388
236
  ```
389
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