ruby/ext
Jean Boussier ee4fa4ccee [ruby/json] json_string_unescape: Use the returned RString as buffer
Rather than to copy into a buffer to unescape and then copy that
buffer into the final string, we can directly copy into the final
string.

The downside is that if the string contains a lot of escaping, we
end up returning a string that's larger than strictly necessary, but
it's probably fine.

Before:

```
== Parsing twitter.json (567916 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
                json    56.000 i/100ms
                  oj    58.000 i/100ms
           oj strict    74.000 i/100ms
          Oj::Parser    76.000 i/100ms
           rapidjson    52.000 i/100ms
Calculating -------------------------------------
                json    556.659 (± 2.9%) i/s    (1.80 ms/i) -      2.800k in   5.034719s
                  oj    604.077 (± 3.8%) i/s    (1.66 ms/i) -      3.016k in   5.001546s
           oj strict    706.942 (± 3.5%) i/s    (1.41 ms/i) -      3.552k in   5.030954s
          Oj::Parser    752.917 (± 3.2%) i/s    (1.33 ms/i) -      3.800k in   5.052707s
           rapidjson    546.470 (± 3.5%) i/s    (1.83 ms/i) -      2.756k in   5.049855s

Comparison:
                json:      556.7 i/s
          Oj::Parser:      752.9 i/s - 1.35x  faster
           oj strict:      706.9 i/s - 1.27x  faster
                  oj:      604.1 i/s - 1.09x  faster
           rapidjson:      546.5 i/s - same-ish: difference falls within error

== Parsing citm_catalog.json (1727030 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
                json    29.000 i/100ms
                  oj    32.000 i/100ms
           oj strict    38.000 i/100ms
          Oj::Parser    42.000 i/100ms
           rapidjson    38.000 i/100ms
Calculating -------------------------------------
                json    317.858 (± 3.1%) i/s    (3.15 ms/i) -      1.595k in   5.023245s
                  oj    348.168 (± 2.6%) i/s    (2.87 ms/i) -      1.760k in   5.058431s
           oj strict    394.599 (± 2.8%) i/s    (2.53 ms/i) -      1.976k in   5.012073s
          Oj::Parser    403.771 (± 3.0%) i/s    (2.48 ms/i) -      2.058k in   5.101578s
           rapidjson    383.441 (± 3.7%) i/s    (2.61 ms/i) -      1.938k in   5.061355s

Comparison:
                json:      317.9 i/s
          Oj::Parser:      403.8 i/s - 1.27x  faster
           oj strict:      394.6 i/s - 1.24x  faster
           rapidjson:      383.4 i/s - 1.21x  faster
                  oj:      348.2 i/s - 1.10x  faster
```

After:

```
== Parsing twitter.json (567916 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
                json    56.000 i/100ms
                  oj    62.000 i/100ms
           oj strict    73.000 i/100ms
          Oj::Parser    76.000 i/100ms
           rapidjson    54.000 i/100ms
Calculating -------------------------------------
                json    561.009 (± 7.5%) i/s    (1.78 ms/i) -      2.800k in   5.039548s
                  oj    601.124 (± 4.3%) i/s    (1.66 ms/i) -      3.038k in   5.064686s
           oj strict    707.455 (± 3.4%) i/s    (1.41 ms/i) -      3.577k in   5.062540s
          Oj::Parser    751.799 (± 3.1%) i/s    (1.33 ms/i) -      3.800k in   5.059509s
           rapidjson    535.641 (± 3.2%) i/s    (1.87 ms/i) -      2.700k in   5.045816s

Comparison:
                json:      561.0 i/s
          Oj::Parser:      751.8 i/s - 1.34x  faster
           oj strict:      707.5 i/s - 1.26x  faster
                  oj:      601.1 i/s - same-ish: difference falls within error
           rapidjson:      535.6 i/s - same-ish: difference falls within error

== Parsing citm_catalog.json (1727030 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
                json    30.000 i/100ms
                  oj    32.000 i/100ms
           oj strict    36.000 i/100ms
          Oj::Parser    42.000 i/100ms
           rapidjson    39.000 i/100ms
Calculating -------------------------------------
                json    313.248 (± 7.3%) i/s    (3.19 ms/i) -      1.560k in   5.014118s
                  oj    341.977 (± 4.1%) i/s    (2.92 ms/i) -      1.728k in   5.063332s
           oj strict    387.062 (± 6.2%) i/s    (2.58 ms/i) -      1.944k in   5.045961s
          Oj::Parser    400.423 (± 4.0%) i/s    (2.50 ms/i) -      2.016k in   5.044513s
           rapidjson    379.046 (± 6.1%) i/s    (2.64 ms/i) -      1.911k in   5.064461s

Comparison:
                json:      313.2 i/s
          Oj::Parser:      400.4 i/s - 1.28x  faster
           oj strict:      387.1 i/s - 1.24x  faster
           rapidjson:      379.0 i/s - 1.21x  faster
                  oj:      342.0 i/s - same-ish: difference falls within error
```

https://github.com/ruby/json/commit/5e1ec4a268
2024-11-01 13:04:24 +09:00
..
-test- Cast via `uintptr_t` function pointer between object pointer 2024-10-10 11:29:57 +09:00
cgi/escape ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
continuation ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
coverage ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
date Resize arrays in `rb_ary_freeze` and use it for freezing arrays 2024-07-02 10:34:23 -07:00
digest [ruby/digest] Cast via `uintptr_t` function pointer between object pointer 2024-10-10 14:45:49 +00:00
erb/escape [ruby/erb] Skip building a native extension for JRuby 2024-01-04 22:33:16 +00:00
etc [ruby/etc] Fix sysconfdir when load-relative 2024-10-17 07:32:38 +00:00
fcntl ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
fiddle Bump version 2024-10-26 18:44:15 +09:00
io [ruby/io-console] Fix mixing declarations and code for older versions 2024-09-01 03:46:44 +00:00
json [ruby/json] json_string_unescape: Use the returned RString as buffer 2024-11-01 13:04:24 +09:00
monitor ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
objspace [Feature #20470] Split GC into gc_impl.c 2024-07-03 09:03:40 -04:00
openssl [ruby/openssl] pkcs7: remove default cipher from PKCS7.encrypt 2024-10-31 08:31:16 +00:00
pathname Allow method chaining with Pathname#mkpath 2024-10-04 12:21:27 +09:00
psych [ruby/psych] Use `String#match?` over `String#=~` when applicable 2024-09-24 19:25:40 +00:00
pty [DOC] Fix typos 2024-10-31 12:44:50 +09:00
rbconfig/sizeof ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
ripper Fix memory leak in Ripper for indented heredocs 2024-09-25 08:56:14 -04:00
rubyvm Added depend files 2019-07-14 01:31:29 +09:00
socket [DOC] Improve `Socket::tcp` with Happy Eyeballs Version 2 2024-10-20 19:26:01 +09:00
stringio [ruby/stringio] An empty string should be converted to empty in any encoding 2024-10-26 13:20:34 +00:00
strscan [ruby/strscan] [CRuby] Optimize `strscan_do_scan()`: Remove 2024-10-26 18:44:15 +09:00
win32 [ruby/win32-registry] Exclude rake files from packages [ci skip] 2024-10-17 03:09:32 +00:00
win32ole [ruby/win32ole] win32ole.c: repeated code 2024-07-12 09:45:06 +00:00
zlib [ruby/zlib] Reduce `ensure` nesting 2024-10-24 10:30:37 +00:00
.document [ruby/io-console] [DOC] Split .document files to sync with ruby/ruby 2023-10-22 11:09:06 +09:00
Setup Clean up removed directories in ext/Setup* [ci skip] 2023-01-18 12:02:27 +09:00
Setup.atheos racc/cparse is extracted from ruby/ruby repository 2023-06-08 18:05:07 +09:00
Setup.nt racc/cparse is extracted from ruby/ruby repository 2023-06-08 18:05:07 +09:00
extmk.rb extmk.rb: define Gem.target_rbconfig not to break `Gem::Platform.local` 2024-06-18 11:12:52 +09:00