Skip to content

Commit 43835a0

Browse files
byrootluke-gru
andcommitted
Speedup Parser initialization
Extracted from: #512 Use `rb_hash_lookup2` to check for hash key existence instead of going through `rb_funcall`. Co-Authored-By: lukeg <luke.gru@gmail.com>
1 parent 8713aa4 commit 43835a0

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

ext/json/ext/parser/parser.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity;
7474

7575
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
7676
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
77-
i_object_class, i_array_class, i_decimal_class, i_key_p,
77+
i_object_class, i_array_class, i_decimal_class,
7878
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
7979
i_leftshift, i_new, i_try_convert, i_freeze, i_uminus;
8080

@@ -2180,7 +2180,6 @@ void Init_parser(void)
21802180
i_decimal_class = rb_intern("decimal_class");
21812181
i_match = rb_intern("match");
21822182
i_match_string = rb_intern("match_string");
2183-
i_key_p = rb_intern("key?");
21842183
i_deep_const_get = rb_intern("deep_const_get");
21852184
i_aset = rb_intern("[]=");
21862185
i_aref = rb_intern("[]");

ext/json/ext/parser/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# define MAYBE_UNUSED(x) x
88
#endif
99

10-
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
10+
#define option_given_p(opts, key) (rb_hash_lookup2(opts, key, Qundef) != Qundef)
1111

1212
typedef struct JSON_ParserStruct {
1313
VALUE Vsource;

ext/json/ext/parser/parser.rl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity;
7272

7373
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
7474
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
75-
i_object_class, i_array_class, i_decimal_class, i_key_p,
75+
i_object_class, i_array_class, i_decimal_class,
7676
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
7777
i_leftshift, i_new, i_try_convert, i_freeze, i_uminus;
7878

@@ -940,7 +940,6 @@ void Init_parser(void)
940940
i_decimal_class = rb_intern("decimal_class");
941941
i_match = rb_intern("match");
942942
i_match_string = rb_intern("match_string");
943-
i_key_p = rb_intern("key?");
944943
i_deep_const_get = rb_intern("deep_const_get");
945944
i_aset = rb_intern("[]=");
946945
i_aref = rb_intern("[]");

0 commit comments

Comments
 (0)