diff options
author | Jean Boussier <[email protected]> | 2024-10-17 19:36:48 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-10-18 11:28:12 +0900 |
commit | c4d4c6b84683f0b5f9a84f29060a40823f3f5fe2 (patch) | |
tree | ad980876350999f995d283b335196fd0d1204207 | |
parent | 5152f81fffca7a5f65ed874603a9761771721029 (diff) |
[ruby/json] Speedup Parser initialization
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 <[email protected]>
-rw-r--r-- | ext/json/parser/parser.c | 3 | ||||
-rw-r--r-- | ext/json/parser/parser.h | 2 | ||||
-rw-r--r-- | ext/json/parser/parser.rl | 3 |
3 files changed, 3 insertions, 5 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index a1947314f8..335b2a20ba 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -74,7 +74,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, - i_object_class, i_array_class, i_decimal_class, i_key_p, + i_object_class, i_array_class, i_decimal_class, i_deep_const_get, i_match, i_match_string, i_aset, i_aref, i_leftshift, i_new, i_try_convert, i_freeze, i_uminus; @@ -2180,7 +2180,6 @@ void Init_parser(void) i_decimal_class = rb_intern("decimal_class"); i_match = rb_intern("match"); i_match_string = rb_intern("match_string"); - i_key_p = rb_intern("key?"); i_deep_const_get = rb_intern("deep_const_get"); i_aset = rb_intern("[]="); i_aref = rb_intern("[]"); diff --git a/ext/json/parser/parser.h b/ext/json/parser/parser.h index e11bddf7c2..9c7f0e7d21 100644 --- a/ext/json/parser/parser.h +++ b/ext/json/parser/parser.h @@ -7,7 +7,7 @@ # define MAYBE_UNUSED(x) x #endif -#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key)) +#define option_given_p(opts, key) (rb_hash_lookup2(opts, key, Qundef) != Qundef) typedef struct JSON_ParserStruct { VALUE Vsource; diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 7425204615..e3b3f325e6 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -72,7 +72,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, - i_object_class, i_array_class, i_decimal_class, i_key_p, + i_object_class, i_array_class, i_decimal_class, i_deep_const_get, i_match, i_match_string, i_aset, i_aref, i_leftshift, i_new, i_try_convert, i_freeze, i_uminus; @@ -943,7 +943,6 @@ void Init_parser(void) i_decimal_class = rb_intern("decimal_class"); i_match = rb_intern("match"); i_match_string = rb_intern("match_string"); - i_key_p = rb_intern("key?"); i_deep_const_get = rb_intern("deep_const_get"); i_aset = rb_intern("[]="); i_aref = rb_intern("[]"); |