summaryrefslogtreecommitdiff
path: root/ext/json/parser
AgeCommit message (Collapse)Author
2024-10-30[ruby/json] Allocate the FBuffer struct on the stackJean Boussier
Ref: https://github.com/ruby/json/issues/655 The actual buffer is still on the heap, but this saves a pair of malloc/free. This helps a lot on micro-benchmarks Before: ``` ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- Oj 531.598k i/100ms JSON reuse 417.666k i/100ms Calculating ------------------------------------- Oj 5.735M (± 1.3%) i/s (174.35 ns/i) - 28.706M in 5.005900s JSON reuse 4.604M (± 1.4%) i/s (217.18 ns/i) - 23.389M in 5.080779s Comparison: Oj: 5735475.6 i/s JSON reuse: 4604380.3 i/s - 1.25x slower ``` After: ``` ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- Oj 518.700k i/100ms JSON reuse 483.370k i/100ms Calculating ------------------------------------- Oj 5.722M (± 1.8%) i/s (174.76 ns/i) - 29.047M in 5.077823s JSON reuse 5.278M (± 1.5%) i/s (189.46 ns/i) - 26.585M in 5.038172s Comparison: Oj: 5722283.8 i/s JSON reuse: 5278061.7 i/s - 1.08x slower ``` Bench: ```ruby require 'benchmark/ips' require 'oj' require 'json' json_encoder = JSON::State.new(JSON.dump_default_options) test_data = [1, "string", { a: 1, b: 2 }, [3, 4, 5]] Oj.default_options = Oj.default_options.merge(mode: :compat) Benchmark.ips do |x| x.config(time: 5, warmup: 2) x.report("Oj") do Oj.dump(test_data) end x.report("JSON reuse") do json_encoder.generate(test_data) end x.compare!(order: :baseline) end ``` https://github.com/ruby/json/commit/72110f7992
2024-10-26[ruby/json] Use smaller types for JSON_Parser boolean fieldsJean Boussier
https://github.com/ruby/json/commit/7f079b25be
2024-10-26[ruby/json] JSON.dump / String#to_json: raise on invalid encodingJean Boussier
This regressed since 2.7.2. https://github.com/ruby/json/commit/35407d6635
2024-10-26[ruby/json] raise_parse_error: avoid UBJean Boussier
Fix: https://github.com/ruby/json/pull/625 Declaring the buffer in a sub block cause bugs on some compilers. https://github.com/ruby/json/commit/90967c9eb0
2024-10-26Use frozen string literalsÉtienne Barrié
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-10-26[ruby/json] Compile with std=c99Jean Boussier
https://github.com/ruby/json/commit/d4968d2e48
2024-10-26[ruby/json] Ext::Parser avoid costly check on decimal_class when it is nilJean Boussier
Closes: https://github.com/ruby/json/pull/512 https://github.com/ruby/json/commit/d882a45d82 Co-Authored-By: lukeg <luke.gru@gmail.com>
2024-10-26[ruby/json] Limit the size of ParserError exception messagesJean Boussier
Fix: https://github.com/ruby/json/issues/534 Only include up to 32 bytes of unparseable the source. https://github.com/ruby/json/commit/f44995cfb6
2024-10-26[ruby/json] parser.c: refactor raise_parse_errorJean Boussier
https://github.com/ruby/json/commit/09e1df2643
2024-10-26[ruby/json] Get rid of the remaining tabs.Jean Boussier
https://github.com/ruby/json/commit/1a9af430d2
2024-10-26Reduce allocations in `parse` and `load` argument handlingJean Boussier
Avoid needless hash allocations and such that degrade performance significantly on micro-benchmarks.
2024-10-26Add more precise documentation for `object_class` and `array_class`Jean Boussier
Fix: https://github.com/ruby/json/issues/419
2024-10-18[ruby/json] Always dup argument to preserve original encoding for force_encodingTakumasa Ochi
https://github.com/ruby/json/commit/db9a489ca2
2024-10-18[ruby/json] Speedup Parser initializationJean Boussier
Extracted from: https://github.com/ruby/json/pull/512 Use `rb_hash_lookup2` to check for hash key existence instead of going through `rb_funcall`. https://github.com/ruby/json/commit/43835a0d13 Co-Authored-By: lukeg <luke.gru@gmail.com>
2024-10-17[ruby/json] Sync changesPeter Zhu
Some changes were missed in the automatic sync. Notes: Merged: https://github.com/ruby/ruby/pull/11911
2024-10-17[ruby/json] Get rid of some more outdated compatibility codeJean Boussier
All these macros are available on Ruby 2.3+ https://github.com/ruby/json/commit/227885f460
2024-10-17[ruby/json] Get rid of compatibility code for older rubiesJean Boussier
All of these are for rubies older than 2.3. https://github.com/ruby/json/commit/811297f86a
2024-10-08[ruby/json] Unicode string like § is not allowed in C files at ruby/ruby repoHiroshi SHIBATA
https://github.com/ruby/json/commit/53409bcc74
2024-10-08[ruby/json] Adjust to the CVTUTF code being goneLuke T. Shumaker
I, Luke T. Shumaker, am the sole author of the added code. I did not reference CVTUTF when writing it. I did reference the Unicode standard (15.0.0), the Wikipedia article on UTF-8, and the Wikipedia article on UTF-16. When I saw some tests fail, I did reference the old deleted code (but a JSON-specific part, inherently not as based on CVTUTF) to determine that script_safe should also escape U+2028 and U+2029. I targeted simplicity and clarity when writing the code--it can likely be optimized. In my mind, the obvious next optimization is to have it combine contiguous non-escaped characters into just one call to fbuffer_append(), instead of calling fbuffer_append() for each character. Regarding the use of the "modern" types `uint32_t`, `uint16_t`, and `bool`: - ruby.h is guaranteed to give us uint32_t and uint16_t. - Since Ruby 3.0.0, ruby.h is guaranteed to give us bool... but we support down to Ruby 2.3. But, ruby.h is guaranteed to give us HAVE_STDBOOL_H for the C99 stdbool.h; so use that to include stdbool.h if we can, and if not then fall back to a copy of the same bool definition that Ruby 3.0.5 uses with C89. https://github.com/ruby/json/commit/c96351f874
2024-10-08[ruby/json] Delete code that is based on CVTUTFLuke T. Shumaker
I did this based on manual inspection, comparing the code to my re-created history of CVTUTF at https://git.lukeshu.com/2git/cvtutf/ (created by the scripts at https://git.lukeshu.com/2git/cvtutf-make/) https://github.com/ruby/json/commit/0819553144
2024-09-03[flori/json] Remove outdated ifdef checksJean Boussier
`json` requires Ruby 2.3, so `HAVE_RUBY_ENCODING_H` and `HAVE_RB_ENC_RAISE` are always true. https://github.com/flori/json/commit/5c8dc6b70a
2024-06-04[flori/json] Cleanup useless ifdefJean Boussier
The json gem now requires Ruby 2.3, so there is no point keeping compatibility code for older releases that don't have the TypedData API. https://github.com/flori/json/commit/45c86e153f
2024-04-27ruby tool/update-deps --fix卜部昌平
2023-12-01Manually merged from flori/jsonHiroshi SHIBATA
> https://github.com/flori/json/pull/525 > Rename escape_slash in script_safe and also escape E+2028 and E+2029 Co-authored-by: Jean Boussier <jean.boussier@gmail.com> > https://github.com/flori/json/pull/454 > Remove unnecessary initialization of create_id in JSON.parse() Co-authored-by: Watson <watson1978@gmail.com>
2023-12-01Use ruby_xfree to free buffersJean Boussier
They are allocated with ruby_xmalloc, they should be freed with ruby_xfree.
2023-12-01[flori/json] Fix "unexpected token" offset for InfinityJohn Hawthorn
Previously in the JSON::Ext parser, when we encountered an "Infinity" token (and weren't allowing NaN/Infinity) we would try to display the "unexpected token" at the character before. https://github.com/flori/json/commit/42ac170712
2023-07-19[flori/json] Re-generate parser.cNobuyoshi Nakada
https://github.com/flori/json/commit/82a75ba98e Notes: Merged: https://github.com/ruby/ruby/pull/8091
2023-07-19[flori/json] [DOC] Remove duplicate sentenceNobuyoshi Nakada
https://github.com/flori/json/commit/ed242667b4 Notes: Merged: https://github.com/ruby/ruby/pull/8091
2023-07-19[flori/json] Remove `HAVE_RB_SCAN_ARGS_OPTIONAL_HASH` checkNobuyoshi Nakada
This macro is defined since ruby 2.1, which is older than the required ruby version. https://github.com/flori/json/commit/dd1d54e78a Notes: Merged: https://github.com/ruby/ruby/pull/8091
2023-07-18[flori/json] Rename JSON::ParseError to JSON:ParserErrorDimitar Haralanov
https://github.com/flori/json/commit/20b80ca317
2023-02-28Update the depend filesMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/7310
2023-02-27Remove intern/gc.h from Make depsMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/7330
2023-02-08Extract include/ruby/internal/attr/packed_struct.hNobuyoshi Nakada
Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the macros bellow: * `RBIMPL_ATTR_PACKED_STRUCT_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_END` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END` Notes: Merged: https://github.com/ruby/ruby/pull/7268
2022-07-29[flori/json] Stop including the parser source __LINE__ in exceptionsJean Boussier
It makes testing for JSON errors very tedious. You either have to use a Regexp or to regularly update all your assertions when JSON is upgraded. https://github.com/flori/json/commit/de9eb1d28e Notes: Merged: https://github.com/ruby/ruby/pull/6200
2022-05-20[flori/json] Fix parser bug for empty string allocationAndrew Bromwich
When `HAVE_RB_ENC_INTERNED_STR` is enabled it is possible to pass through a null pointer to `rb_enc_interned_str` resulting in a segfault Fixes #495 https://github.com/flori/json/commit/b59368a8c2
2022-05-20[flori/json] Doc: Improve documentation on JSON#parse and JSON#parse!Hiroshi SHIBATA
https://github.com/flori/json/commit/75ada77b96 Co-authored-by: Bruno Gomes da Silva <brunojabs@gmail.com>
2022-02-22[Feature #18249] Update dependenciesPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/5474
2021-11-21Update dependenciesNobuyoshi Nakada
2021-10-05ruby tool/update-deps --fix卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/4909
2021-05-19ext/json/parser/parser.h: Add fallback MAYBE_UNUSEDNobuyoshi Nakada
https://github.com/flori/json/commit/e2ad91fc2094d3cc2f76adc6c55d420cd06f34d8
2021-05-18ext/json/parser/prereq.mk: fix warnings for code generated by ragelNobuyoshi Nakada
* type-limits when plain-char is unsigned * unused-const-variable for NFA constants
2021-05-17[flori/json] Deduplicate strings inside json_string_unescapeJean Boussier
[ci 2] https://github.com/flori/json/commit/1982070cb8
2021-05-17[flori/json] Refactor json_string_unescapeJean Boussier
https://github.com/flori/json/commit/f398769332
2021-04-13dependency updates卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/4371
2020-12-21[json] Make json Ractor safeKenta Murata
2020-12-21[json] JSON_parse_float: Fix how to convert numberKenta Murata
Stop BigDecimal-specific optimization. Instead, it tries the conversion methods in the following order: 1. `try_convert`, 2. `new`, and 3. class-named function, e.g. `Foo::Bar.Baz` function for `Foo::Bar::Baz` class If all the above candidates are unavailable, it fallbacks to Float.
2020-10-20Implement a freeze: parser optionJean Boussier
If set to true all parsed objects will be immediately frozen, and strings will be deduplicated if the Ruby implementation allows it.
2020-08-27sed -i '/rmodule.h/d'卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3347
2020-08-27sed -i '/r_cast.h/d'卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3346
2020-08-27sed -i '\,2/extern.h,d'卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3338