Skip to content

Commit

Permalink
Fetch the last element only when not empty
Browse files Browse the repository at this point in the history
Also `flag_keyword_hash` sets to 0 or a hash object.
  • Loading branch information
nobu committed Aug 4, 2023
1 parent 0dc0c24 commit 48f0352
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions vm_args.c
Expand Up @@ -560,11 +560,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
args->rest = locals[--args->argc];
int len = RARRAY_LENINT(args->rest);
given_argc += len - 1;
rest_last = RARRAY_AREF(args->rest, len - 1);

if (!kw_flag && len > 0) {
if (RB_TYPE_P(rest_last, T_HASH) &&
(((struct RHash *)rest_last)->basic.flags & RHASH_PASS_AS_KEYWORDS)) {
rest_last = RARRAY_AREF(args->rest, len - 1);
if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
// def f(**kw); a = [..., kw]; g(*a)
splat_flagged_keyword_hash = rest_last;
rest_last = rb_hash_dup(rest_last);
Expand Down Expand Up @@ -595,9 +594,6 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
}
}
}
else {
rest_last = 0;
}
}
else {
args->rest = Qfalse;
Expand Down Expand Up @@ -628,8 +624,8 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
}
}

if (flag_keyword_hash && RB_TYPE_P(flag_keyword_hash, T_HASH)) {
((struct RHash *)flag_keyword_hash)->basic.flags |= RHASH_PASS_AS_KEYWORDS;
if (flag_keyword_hash) {
FL_SET_RAW(flag_keyword_hash, RHASH_PASS_AS_KEYWORDS);
}

if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
Expand Down

0 comments on commit 48f0352

Please sign in to comment.