diff options
author | Jean Boussier <[email protected]> | 2024-10-18 12:27:17 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-10-26 18:44:15 +0900 |
commit | e0f8732023c50ee72ed132ebebc9e858643ba6b0 (patch) | |
tree | a64b117b3eee8c726783228cd071838607b46d3a /ext/json/parser/parser.rl | |
parent | 8e7e63822123568e677ad34cf5350d970eca4a17 (diff) |
Reduce allocations in `parse` and `load` argument handling
Avoid needless hash allocations and such that degrade performance
significantly on micro-benchmarks.
Diffstat (limited to 'ext/json/parser/parser.rl')
-rw-r--r-- | ext/json/parser/parser.rl | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 2b1c743dbd..da4f7f919a 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -719,7 +719,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) if (json->Vsource) { rb_raise(rb_eTypeError, "already initialized instance"); } - rb_scan_args(argc, argv, "1:", &source, &opts); + + rb_check_arity(argc, 1, 2); + source = argv[0]; + opts = Qnil; + if (argc == 2) { + opts = argv[1]; + Check_Type(opts, T_HASH); + } + if (!NIL_P(opts)) { VALUE tmp = ID2SYM(i_max_nesting); if (option_given_p(opts, tmp)) { |