summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-20 03:37:22 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-20 03:37:22 +0000
commit243842f68a97a34a36a7e8c690efe7e18bf81e91 (patch)
tree01e3cc7f31dd70d6bb1e1e44bc83d576eb031456 /compile.c
parent27f75cf3dc74ad70d065a7d8a14dbaa0eeac1023 (diff)
Avoid usage of the dummy empty BEGIN node
Use NODE_SPECIAL_NO_NAME_REST instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/compile.c b/compile.c
index 6d6d9e1c8f..2dbfb5497e 100644
--- a/compile.c
+++ b/compile.c
@@ -5305,8 +5305,8 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
const int post_args_num = apinfo->post_args ? rb_long2int(apinfo->post_args->nd_alen) : 0;
const int min_argc = pre_args_num + post_args_num;
- const int use_rest_num = apinfo->rest_arg && ((nd_type(apinfo->rest_arg) != NODE_BEGIN) ||
- (nd_type(apinfo->rest_arg) == NODE_BEGIN && post_args_num > 0));
+ const int use_rest_num = apinfo->rest_arg && (NODE_NAMED_REST_P(apinfo->rest_arg) ||
+ (!NODE_NAMED_REST_P(apinfo->rest_arg) && post_args_num > 0));
LABEL *match_failed, *type_error, *fin;
int i;
@@ -5354,17 +5354,7 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
}
if (apinfo->rest_arg) {
- if (nd_type(apinfo->rest_arg) == NODE_BEGIN) {
- if (post_args_num > 0) {
- ADD_INSN(ret, line, dup);
- ADD_SEND(ret, line, idLength, INT2FIX(0));
- ADD_INSN1(ret, line, putobject, INT2FIX(min_argc));
- ADD_SEND(ret, line, idMINUS, INT2FIX(1));
- ADD_INSN1(ret, line, setn, INT2FIX(2));
- ADD_INSN(ret, line, pop);
- }
- }
- else {
+ if (NODE_NAMED_REST_P(apinfo->rest_arg)) {
ADD_INSN(ret, line, dup);
ADD_INSN1(ret, line, putobject, INT2FIX(pre_args_num));
ADD_INSN1(ret, line, topn, INT2FIX(1));
@@ -5377,6 +5367,16 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
iseq_compile_pattern_each(iseq, ret, apinfo->rest_arg, in_alt_pattern);
ADD_INSNL(ret, line, branchunless, match_failed);
}
+ else {
+ if (post_args_num > 0) {
+ ADD_INSN(ret, line, dup);
+ ADD_SEND(ret, line, idLength, INT2FIX(0));
+ ADD_INSN1(ret, line, putobject, INT2FIX(min_argc));
+ ADD_SEND(ret, line, idMINUS, INT2FIX(1));
+ ADD_INSN1(ret, line, setn, INT2FIX(2));
+ ADD_INSN(ret, line, pop);
+ }
+ }
}
args = apinfo->post_args;