ruby-changes:62154
From: Nobuyoshi <ko1@a...>
Date: Wed, 8 Jul 2020 21:35:15 +0900 (JST)
Subject: [ruby-changes:62154] 11af12026e (master): Hoisted out functions for no name rest argument symbol
https://git.ruby-lang.org/ruby.git/commit/?id=11af12026e From 11af12026eff782c18244d8b5f431f73cdf29dd2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 8 Jul 2020 18:26:57 +0900 Subject: Hoisted out functions for no name rest argument symbol diff --git a/ast.c b/ast.c index 6650966..87c3665 100644 --- a/ast.c +++ b/ast.c @@ -307,6 +307,20 @@ var_name(ID id) https://github.com/ruby/ruby/blob/trunk/ast.c#L307 } static VALUE +no_name_rest(void) +{ + ID rest; + CONST_ID(rest, "NODE_SPECIAL_NO_NAME_REST"); + return ID2SYM(rest); +} + +static VALUE +rest_arg(rb_ast_t *ast, const NODE *rest_arg) +{ + return NODE_NAMED_REST_P(rest_arg) ? NEW_CHILD(ast, rest_arg) : no_name_rest(); +} + +static VALUE node_children(rb_ast_t *ast, const NODE *node) { char name[DECIMAL_SIZE_OF_BITS(sizeof(long) * CHAR_BIT) + 2]; /* including '$' */ @@ -375,7 +389,7 @@ node_children(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L389 else { return rb_ary_new_from_args(3, NEW_CHILD(ast, node->nd_value), NEW_CHILD(ast, node->nd_head), - ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST"))); + no_name_rest()); } case NODE_LASGN: case NODE_DASGN: @@ -535,7 +549,7 @@ node_children(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L549 if (NODE_NAMED_REST_P(node->nd_1st)) { return rb_ary_new_from_node_args(ast, 2, node->nd_1st, node->nd_2nd); } - return rb_ary_new_from_args(2, ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST")), + return rb_ary_new_from_args(2, no_name_rest(), NEW_CHILD(ast, node->nd_2nd)); case NODE_ARGS: { @@ -567,8 +581,7 @@ node_children(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L581 case NODE_ARYPTN: { struct rb_ary_pattern_info *apinfo = node->nd_apinfo; - VALUE rest = NODE_NAMED_REST_P(apinfo->rest_arg) ? NEW_CHILD(ast, apinfo->rest_arg) : - ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST")); + VALUE rest = rest_arg(ast, apinfo->rest_arg); return rb_ary_new_from_args(4, NEW_CHILD(ast, node->nd_pconst), NEW_CHILD(ast, apinfo->pre_args), @@ -578,10 +591,8 @@ node_children(rb_ast_t *ast, const NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L591 case NODE_FNDPTN: { struct rb_fnd_pattern_info *fpinfo = node->nd_fpinfo; - VALUE pre_rest = NODE_NAMED_REST_P(fpinfo->pre_rest_arg) ? NEW_CHILD(ast, fpinfo->pre_rest_arg) : - ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST")); - VALUE post_rest = NODE_NAMED_REST_P(fpinfo->post_rest_arg) ? NEW_CHILD(ast, fpinfo->post_rest_arg) : - ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST")); + VALUE pre_rest = rest_arg(ast, fpinfo->pre_rest_arg); + VALUE post_rest = rest_arg(ast, fpinfo->post_rest_arg); return rb_ary_new_from_args(4, NEW_CHILD(ast, node->nd_pconst), pre_rest, -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/