diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-07 18:54:01 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-07 20:25:12 +0900 |
commit | 187328b7037e54f1f5c2558d84215f3d5d3fbdee (patch) | |
tree | 02dd244a2c1cc84d86e3972f4955c4565a899ad8 /compile.c | |
parent | 324dd9d01f0c97631a2588f63231bcb651844cca (diff) |
compile.c (compile_array): refactoring
"popped" case can be so simple, so this change moves the branch to the
first, instead of scattering `if (popped)` branches to the main part.
Also, the return value "len" is not used. So it returns just 0 or 1.
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 136 |
1 files changed, 67 insertions, 69 deletions
@@ -3919,95 +3919,93 @@ static int compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped) { int line = (int)nd_line(node); - int len = 0; if (nd_type(node) == NODE_ZLIST) { if (!popped) { ADD_INSN1(ret, line, newarray, INT2FIX(0)); } + return 0; } - else { - int opt_p = 1; - int first = 1, i; - while (node) { - const NODE *start_node = node, *end_node, *prev_node; - const int max = 0x100; - DECL_ANCHOR(anchor); - INIT_ANCHOR(anchor); + EXPECT_NODE("compile_array", node, NODE_LIST, -1); - for (i=0; i<max && node; i++, len++, prev_node = node, node = node->nd_next) { - if (CPDEBUG > 0) { - EXPECT_NODE("compile_array", node, NODE_LIST, -1); - } + if (popped) { + for (; node; node = node->nd_next) { + NO_CHECK(COMPILE_(ret, "array element", node->nd_head, popped)); + } + return 1; + } - if (opt_p && !static_literal_node_p(node, iseq)) { - opt_p = 0; - } + int opt_p = 1; + int first = 1, i; - NO_CHECK(COMPILE_(anchor, "array element", node->nd_head, popped)); - } + while (node) { + const NODE *start_node = node, *end_node, *prev_node; + const int max = 0x100; + DECL_ANCHOR(anchor); + INIT_ANCHOR(anchor); + + for (i=0; i<max && node; i++, prev_node = node, node = node->nd_next) { + if (CPDEBUG > 0) { + EXPECT_NODE("compile_array", node, NODE_LIST, -1); + } - if (opt_p) { - if (!popped) { - VALUE ary = rb_ary_tmp_new(i); + if (opt_p && !static_literal_node_p(node, iseq)) { + opt_p = 0; + } - end_node = node; - node = start_node; + NO_CHECK(COMPILE_(anchor, "array element", node->nd_head, 0)); + } - while (node != end_node) { - rb_ary_push(ary, static_literal_value(node, iseq)); - node = node->nd_next; - } - while (node && static_literal_node_p(node, iseq)) { - rb_ary_push(ary, static_literal_value(node, iseq)); - node = node->nd_next; - len++; - } + if (opt_p) { + VALUE ary = rb_ary_tmp_new(i); - OBJ_FREEZE(ary); + end_node = node; + node = start_node; - iseq_add_mark_object_compile_time(iseq, ary); + while (node != end_node) { + rb_ary_push(ary, static_literal_value(node, iseq)); + node = node->nd_next; + } + while (node && static_literal_node_p(node, iseq)) { + rb_ary_push(ary, static_literal_value(node, iseq)); + node = node->nd_next; + } - if (first) { - first = 0; - ADD_INSN1(ret, line, duparray, ary); - } - else { - ADD_INSN1(ret, line, putobject, ary); - ADD_INSN(ret, line, concatarray); - } - } - } - else { - if (!popped) { - /* Find last node in array, and if it is a keyword argument, then set - flag to check and remove empty keyword arguments hash from array */ - if (!node && nd_type(prev_node->nd_head) == NODE_HASH && prev_node->nd_head->nd_brace == 0) { - ADD_INSN1(anchor, line, newarraykwsplat, INT2FIX(i)); - } - else { - ADD_INSN1(anchor, line, newarray, INT2FIX(i)); - } + OBJ_FREEZE(ary); + iseq_add_mark_object_compile_time(iseq, ary); - if (first) { - first = 0; - } - else { - ADD_INSN(anchor, line, concatarray); - } + if (first) { + first = 0; + ADD_INSN1(ret, line, duparray, ary); + } + else { + ADD_INSN1(ret, line, putobject, ary); + ADD_INSN(ret, line, concatarray); + } + } + else { + /* Find last node in array, and if it is a keyword argument, then set + flag to check and remove empty keyword arguments hash from array */ + if (!node && nd_type(prev_node->nd_head) == NODE_HASH && prev_node->nd_head->nd_brace == 0) { + ADD_INSN1(anchor, line, newarraykwsplat, INT2FIX(i)); + } + else { + ADD_INSN1(anchor, line, newarray, INT2FIX(i)); + } - APPEND_LIST(ret, anchor); - } - else { - /* popped */ - APPEND_LIST(ret, anchor); - } - } - } + if (first) { + first = 0; + } + else { + ADD_INSN(anchor, line, concatarray); + } + + APPEND_LIST(ret, anchor); + } } - return len; + return 1; } static int |