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

ruby-changes:57659

From: Yusuke <ko1@a...>
Date: Sun, 8 Sep 2019 00:45:23 +0900 (JST)
Subject: [ruby-changes:57659] 95f9d7c76d (master): compile.c (keyword_node_p): Refactor out keyword node checks

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

From 95f9d7c76d9e808099f89e5cf160306680dc5994 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sun, 8 Sep 2019 00:21:23 +0900
Subject: compile.c (keyword_node_p): Refactor out keyword node checks


diff --git a/compile.c b/compile.c
index 0a69ecc..4bae114 100644
--- a/compile.c
+++ b/compile.c
@@ -3795,6 +3795,12 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co https://github.com/ruby/ruby/blob/trunk/compile.c#L3795
 }
 
 static int
+keyword_node_p(const NODE *const node)
+{
+    return nd_type(node) == NODE_HASH && node->nd_brace == FALSE;
+}
+
+static int
 compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
 			  const NODE *const root_node,
 			  struct rb_call_info_kw_arg **const kw_arg_ptr,
@@ -3802,7 +3808,7 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L3808
 {
     if (kw_arg_ptr == NULL) return FALSE;
 
-    if (nd_type(root_node) == NODE_HASH && !root_node->nd_brace && root_node->nd_head && nd_type(root_node->nd_head) == NODE_LIST) {
+    if (keyword_node_p(root_node) && root_node->nd_head && nd_type(root_node->nd_head) == NODE_LIST) {
 	const NODE *node = root_node->nd_head;
 
 	while (node) {
@@ -4028,7 +4034,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int pop https://github.com/ruby/ruby/blob/trunk/compile.c#L4034
             NO_CHECK(COMPILE_(ret, "array element", node->nd_head, 0));
             stack_len++;
 
-            if (!node->nd_next && nd_type(node->nd_head) == NODE_HASH && node->nd_head->nd_brace == 0) {
+            if (!node->nd_next && keyword_node_p(node->nd_head)) {
                 /* Reached the end, and the last element is a keyword */
                 FLUSH_CHUNK(newarraykwsplat);
                 return 1;
@@ -4884,8 +4890,7 @@ check_keyword(const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L4890
         node = node->nd_head;
     }
 
-    if (nd_type(node) == NODE_HASH && !node->nd_brace) return TRUE;
-    return FALSE;
+    return keyword_node_p(node);
 }
 
 static VALUE
-- 
cgit v0.10.2


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

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