mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
Reduce allocations in parse
and load
argument handling
Avoid needless hash allocations and such that degrade performance significantly on micro-benchmarks.
This commit is contained in:
parent
8e7e638221
commit
e0f8732023
3 changed files with 48 additions and 20 deletions
|
@ -1824,7 +1824,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)) {
|
||||
|
@ -1916,7 +1924,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|||
}
|
||||
|
||||
|
||||
#line 1920 "parser.c"
|
||||
#line 1928 "parser.c"
|
||||
enum {JSON_start = 1};
|
||||
enum {JSON_first_final = 10};
|
||||
enum {JSON_error = 0};
|
||||
|
@ -1924,7 +1932,7 @@ enum {JSON_error = 0};
|
|||
enum {JSON_en_main = 1};
|
||||
|
||||
|
||||
#line 828 "parser.rl"
|
||||
#line 836 "parser.rl"
|
||||
|
||||
|
||||
/*
|
||||
|
@ -1942,16 +1950,16 @@ static VALUE cParser_parse(VALUE self)
|
|||
GET_PARSER;
|
||||
|
||||
|
||||
#line 1946 "parser.c"
|
||||
#line 1954 "parser.c"
|
||||
{
|
||||
cs = JSON_start;
|
||||
}
|
||||
|
||||
#line 845 "parser.rl"
|
||||
#line 853 "parser.rl"
|
||||
p = json->source;
|
||||
pe = p + json->len;
|
||||
|
||||
#line 1955 "parser.c"
|
||||
#line 1963 "parser.c"
|
||||
{
|
||||
if ( p == pe )
|
||||
goto _test_eof;
|
||||
|
@ -1985,7 +1993,7 @@ st0:
|
|||
cs = 0;
|
||||
goto _out;
|
||||
tr2:
|
||||
#line 820 "parser.rl"
|
||||
#line 828 "parser.rl"
|
||||
{
|
||||
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
||||
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
||||
|
@ -1995,7 +2003,7 @@ st10:
|
|||
if ( ++p == pe )
|
||||
goto _test_eof10;
|
||||
case 10:
|
||||
#line 1999 "parser.c"
|
||||
#line 2007 "parser.c"
|
||||
switch( (*p) ) {
|
||||
case 13: goto st10;
|
||||
case 32: goto st10;
|
||||
|
@ -2084,7 +2092,7 @@ case 9:
|
|||
_out: {}
|
||||
}
|
||||
|
||||
#line 848 "parser.rl"
|
||||
#line 856 "parser.rl"
|
||||
|
||||
if (cs >= JSON_first_final && p == pe) {
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue