[ruby/json] Refactor JSON::Ext::Parser to split configuration and parsing state

Ref: https://github.com/ruby/json/pull/718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

c8d5236a92

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
This commit is contained in:
Jean Boussier 2025-01-13 14:04:15 +01:00
parent c8d11edcf5
commit 599fbeaffa
5 changed files with 585 additions and 765 deletions

View file

@ -6,11 +6,11 @@ class JSONExtParserTest < Test::Unit::TestCase
def test_allocate
parser = JSON::Ext::Parser.new("{}")
assert_raise(TypeError, '[ruby-core:35079]') do
parser.__send__(:initialize, "{}")
end
parser.__send__(:initialize, "{}")
assert_equal "{}", parser.source
parser = JSON::Ext::Parser.allocate
assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
assert_nil parser.source
end
def test_error_messages