[前][次][番号順一覧][スレッド一覧]

ruby-changes:61977

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:06:23 +0900 (JST)
Subject: [ruby-changes:61977] e634a9d1a5 (master): node_children: do not goto into a branch

https://git.ruby-lang.org/ruby.git/commit/?id=e634a9d1a5

From e634a9d1a562ad28385de5a6a298ea84ab11c5fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Thu, 11 Jun 2020 12:00:43 +0900
Subject: node_children: do not goto into a branch

Was this an autogenerated function?  This tendency of avoiding empty
branches are no longer preserved (see for instance NODE_IVAR).  Let's
just delete those unnecessary jumps into branches.

diff --git a/ast.c b/ast.c
index 44fec16..e43f6f8 100644
--- a/ast.c
+++ b/ast.c
@@ -330,9 +330,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L330
       case NODE_IN:
         return rb_ary_new_from_node_args(ast, 3, node->nd_head, node->nd_body, node->nd_next);
       case NODE_WHILE:
-        goto loop;
       case NODE_UNTIL:
-      loop:
         return rb_ary_push(rb_ary_new_from_node_args(ast, 2, node->nd_cond, node->nd_body),
                            (node->nd_state ? Qtrue : Qfalse));
       case NODE_ITER:
@@ -341,11 +339,8 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L339
       case NODE_FOR_MASGN:
         return rb_ary_new_from_node_args(ast, 1, node->nd_var);
       case NODE_BREAK:
-        goto jump;
       case NODE_NEXT:
-        goto jump;
       case NODE_RETURN:
-      jump:
         return rb_ary_new_from_node_args(ast, 1, node->nd_stts);
       case NODE_REDO:
         return rb_ary_new_from_node_args(ast, 0);
@@ -360,9 +355,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L355
       case NODE_ENSURE:
         return rb_ary_new_from_node_args(ast, 2, node->nd_head, node->nd_ensr);
       case NODE_AND:
-        goto andor;
       case NODE_OR:
-      andor:
         {
             VALUE ary = rb_ary_new();
 
@@ -385,21 +378,15 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L378
                                         ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST")));
         }
       case NODE_LASGN:
-        goto asgn;
       case NODE_DASGN:
-        goto asgn;
       case NODE_DASGN_CURR:
-        goto asgn;
       case NODE_IASGN:
-        goto asgn;
       case NODE_CVASGN:
-      asgn:
+      case NODE_GASGN:
         if (NODE_REQUIRED_KEYWORD_P(node)) {
             return rb_ary_new_from_args(2, var_name(node->nd_vid), ID2SYM(rb_intern("NODE_SPECIAL_REQUIRED_KEYWORD")));
         }
         return rb_ary_new_from_args(2, var_name(node->nd_vid), NEW_CHILD(ast, node->nd_value));
-      case NODE_GASGN:
-        goto asgn;
       case NODE_CDECL:
         if (node->nd_vid) {
             return rb_ary_new_from_args(2, ID2SYM(node->nd_vid), NEW_CHILD(ast, node->nd_value));
@@ -441,9 +428,7 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L428
       case NODE_ZSUPER:
         return rb_ary_new_from_node_args(ast, 0);
       case NODE_LIST:
-        goto ary;
       case NODE_VALUES:
-      ary:
         return dump_array(ast, node);
       case NODE_ZLIST:
         return rb_ary_new_from_node_args(ast, 0);
@@ -467,8 +452,6 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L452
         name[1] = (char)node->nd_nth;
         name[2] = '\0';
         return rb_ary_new_from_args(1, ID2SYM(rb_intern(name)));
-      case NODE_MATCH:
-        goto lit;
       case NODE_MATCH2:
         if (node->nd_args) {
             return rb_ary_new_from_node_args(ast, 3, node->nd_recv, node->nd_value, node->nd_args);
@@ -476,23 +459,17 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L459
         return rb_ary_new_from_node_args(ast, 2, node->nd_recv, node->nd_value);
       case NODE_MATCH3:
         return rb_ary_new_from_node_args(ast, 2, node->nd_recv, node->nd_value);
+      case NODE_MATCH:
       case NODE_LIT:
-        goto lit;
       case NODE_STR:
-        goto lit;
       case NODE_XSTR:
-      lit:
         return rb_ary_new_from_args(1, node->nd_lit);
       case NODE_ONCE:
         return rb_ary_new_from_node_args(ast, 1, node->nd_body);
       case NODE_DSTR:
-        goto dlit;
       case NODE_DXSTR:
-        goto dlit;
       case NODE_DREGX:
-        goto dlit;
       case NODE_DSYM:
-      dlit:
         return rb_ary_new_from_args(3, node->nd_lit,
                                     NEW_CHILD(ast, node->nd_next->nd_head),
                                     NEW_CHILD(ast, node->nd_next->nd_next));
@@ -527,13 +504,9 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L504
       case NODE_COLON3:
         return rb_ary_new_from_args(1, ID2SYM(node->nd_mid));
       case NODE_DOT2:
-        goto dot;
       case NODE_DOT3:
-        goto dot;
       case NODE_FLIP2:
-        goto dot;
       case NODE_FLIP3:
-      dot:
         return rb_ary_new_from_node_args(ast, 2, node->nd_beg, node->nd_end);
       case NODE_SELF:
         return rb_ary_new_from_node_args(ast, 0);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]