summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-22 06:47:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-22 06:47:53 +0000
commit721b55d70c69aa4cf6386c7876df6ffe0b51ef80 (patch)
tree4ec009b9b507be947bf3485be75896195b613150 /parse.y
parentb6e2c52857056b41de8391816fe373de47f32c84 (diff)
downloadruby-721b55d70c69aa4cf6386c7876df6ffe0b51ef80.tar.gz
parse.y: reorder in the place
* parse.y (new_args_tail): reorder required and optional keyword argument variable IDs in the place. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y34
1 files changed, 13 insertions, 21 deletions
diff --git a/parse.y b/parse.y
index 845face90f..f838d3cb05 100644
--- a/parse.y
+++ b/parse.y
@@ -9963,37 +9963,29 @@ new_args_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, ID block,
* #=> <reorder>
* variable order: kr1, k1, k2, internal_id, krest, &b
*/
- ID kw_bits;
+ ID kw_bits = internal_id(p), *required_kw_vars, *kw_vars;
+ struct vtable *vtargs = p->lvtbl->args;
NODE *kwn = kw_args;
- struct vtable *required_kw_vars = vtable_alloc(NULL);
- struct vtable *kw_vars = vtable_alloc(NULL);
- int i;
+ vtable_pop(vtargs, !!block + !!kw_rest_arg);
+ required_kw_vars = kw_vars = &vtargs->tbl[vtargs->pos];
while (kwn) {
- ID vid = kwn->nd_body->nd_vid;
+ if (!NODE_REQUIRED_KEYWORD_P(kwn->nd_body))
+ --kw_vars;
+ --required_kw_vars;
+ kwn = kwn->nd_next;
+ }
+ for (kwn = kw_args; kwn; kwn = kwn->nd_next) {
+ ID vid = kwn->nd_body->nd_vid;
if (NODE_REQUIRED_KEYWORD_P(kwn->nd_body)) {
- vtable_add(required_kw_vars, vid);
+ *required_kw_vars++ = vid;
}
else {
- vtable_add(kw_vars, vid);
+ *kw_vars++ = vid;
}
-
- kwn = kwn->nd_next;
}
- kw_bits = internal_id(p);
-
- /* reorder */
- vtable_pop(p->lvtbl->args,
- vtable_size(required_kw_vars) + vtable_size(kw_vars)
- + (block != 0) + (kw_rest_arg != 0));
-
- for (i=0; i<vtable_size(required_kw_vars); i++) arg_var(p, required_kw_vars->tbl[i]);
- for (i=0; i<vtable_size(kw_vars); i++) arg_var(p, kw_vars->tbl[i]);
- vtable_free(required_kw_vars);
- vtable_free(kw_vars);
-
arg_var(p, kw_bits);
if (kw_rest_arg) arg_var(p, kw_rest_arg);
if (block) arg_var(p, block);