diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-11-03 11:45:43 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-11-03 10:46:26 +0000 |
| commit | 52a17bbe6d778d56cc600f73f107c1992350f877 (patch) | |
| tree | 38033729a7ac0f8382d21a3726622065bc5c94bc | |
| parent | 0832e954c9ef181563be0e70ba089ed0a8c0d02e (diff) | |
[ruby/json] parser.c: use `rb_str_to_interned_str` over `rb_funcall`
https://github.com/ruby/json/commit/21284ea649
| -rw-r--r-- | ext/json/parser/extconf.rb | 1 | ||||
| -rw-r--r-- | ext/json/parser/parser.c | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/ext/json/parser/extconf.rb b/ext/json/parser/extconf.rb index dc1c8952c6..cda385767c 100644 --- a/ext/json/parser/extconf.rb +++ b/ext/json/parser/extconf.rb @@ -3,6 +3,7 @@ require 'mkmf' $defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"] have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0 +have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0 have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2 have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby have_func("strnlen", "string.h") # Missing on Solaris 10 diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index 1e83dad915..25eeb89e77 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -16,7 +16,7 @@ static int utf8_encindex; #ifndef HAVE_RB_HASH_BULK_INSERT // For TruffleRuby -void +static void rb_hash_bulk_insert(long count, const VALUE *pairs, VALUE hash) { long index = 0; @@ -33,6 +33,12 @@ rb_hash_bulk_insert(long count, const VALUE *pairs, VALUE hash) #define rb_hash_new_capa(n) rb_hash_new() #endif +#ifndef HAVE_RB_STR_TO_INTERNED_STR +static VALUE rb_str_to_interned_str(VALUE str) +{ + return rb_funcall(rb_str_freeze(str), i_uminus, 0); +} +#endif /* name cache */ @@ -703,7 +709,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c if (symbolize) { result = rb_str_intern(result); } else if (intern) { - result = rb_funcall(rb_str_freeze(result), i_uminus, 0); + result = rb_str_to_interned_str(result); } return result; @@ -1310,6 +1316,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) } raise_parse_error("unreachable: %s", state); + return Qundef; } static void json_ensure_eof(JSON_ParserState *state) |
