diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-08 00:21:23 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-08 00:28:03 +0900 |
commit | 95f9d7c76d9e808099f89e5cf160306680dc5994 (patch) | |
tree | 113d4f8376f83beb2f747212abe452ae219ae7f5 /compile.c | |
parent | 86b74d1a7389ceaccdc2822b1bbe0a91dc50db99 (diff) | |
download | ruby-95f9d7c76d9e808099f89e5cf160306680dc5994.tar.gz |
compile.c (keyword_node_p): Refactor out keyword node checks
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -3795,6 +3795,12 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co } 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, { 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 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) node = node->nd_head; } - if (nd_type(node) == NODE_HASH && !node->nd_brace) return TRUE; - return FALSE; + return keyword_node_p(node); } static VALUE |