diff options
author | Jean Boussier <[email protected]> | 2025-01-31 12:38:15 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-02-03 10:05:25 +0900 |
commit | 98e1c2845a8361b69820c41b05eddbe5dbf8cf58 (patch) | |
tree | 65529837959261e63887cb4f1ac7406ef4c3b59a /test/json/json_generator_test.rb | |
parent | 581d85058cf638f2f8ad87391dccc5c7708d597b (diff) |
[ruby/json] Refactor convert_UTF8_to_JSON to split searching and escaping code
The goal is to be able to dispatch to more optimized search implementations
without having to duplicate the escaping code.
Somehow, this is a few % faster already:
```
== Encoding activitypub.json (52595 bytes)
ruby 3.4.1 (2024-12-25 revision https://github.com/ruby/json/commit/48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
after 2.257k i/100ms
Calculating -------------------------------------
after 22.930k (± 1.3%) i/s (43.61 μs/i) - 115.107k in 5.020814s
Comparison:
before: 21604.0 i/s
after: 22930.1 i/s - 1.06x faster
== Encoding citm_catalog.json (500298 bytes)
ruby 3.4.1 (2024-12-25 revision https://github.com/ruby/json/commit/48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
after 137.000 i/100ms
Calculating -------------------------------------
after 1.397k (± 1.1%) i/s (715.57 μs/i) - 6.987k in 5.000408s
Comparison:
before: 1344.4 i/s
after: 1397.5 i/s - 1.04x faster
== Encoding twitter.json (466906 bytes)
ruby 3.4.1 (2024-12-25 revision https://github.com/ruby/json/commit/48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
after 249.000 i/100ms
Calculating -------------------------------------
after 2.464k (± 1.8%) i/s (405.81 μs/i) - 12.450k in 5.054131s
Comparison:
before: 2326.5 i/s
after: 2464.2 i/s - 1.06x faster
```
https://github.com/ruby/json/commit/8fb5ae807f
Diffstat (limited to 'test/json/json_generator_test.rb')
-rwxr-xr-x | test/json/json_generator_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb index 7eb95c62de..d97f0505f7 100755 --- a/test/json/json_generator_test.rb +++ b/test/json/json_generator_test.rb @@ -665,6 +665,12 @@ class JSONGeneratorTest < Test::Unit::TestCase assert_equal("\"5\u{b0}\"", "5\xb0".dup.force_encoding(Encoding::ISO_8859_1).to_json) end + def test_utf8_multibyte + assert_equal('["foßbar"]', JSON.generate(["foßbar"])) + assert_equal('"n€ßt€ð2"', JSON.generate("n€ßt€ð2")) + assert_equal('"\"\u0000\u001f"', JSON.generate("\"\u0000\u001f")) + end + def test_fragment fragment = JSON::Fragment.new(" 42") assert_equal '{"number": 42}', JSON.generate({ number: fragment }) |