Skip to content

Commit

Permalink
Eliminate array allocation for f(*a, kw: 1)
Browse files Browse the repository at this point in the history
In cases where the compiler can detect the hash is static, it would
use duphash for the hash part. As the hash is static, there is no need
to allocate an array.
  • Loading branch information
jeremyevans committed Dec 7, 2023
1 parent 9561587 commit 5e33f2b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions compile.c
Expand Up @@ -3917,6 +3917,29 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
}
}
}
} else if (IS_NEXT_INSN_ID(niobj, duphash)) {
niobj = niobj->next;

/*
* Eliminate array allocation for f(*a, kw: 1)
*
* splatarray true
* duphash
* send ARGS_SPLAT|KW_SPLAT|KW_SPLAT_MUT and not ARGS_BLOCKARG
* =>
* splatarray false
* duphash
* send
*/
if (IS_NEXT_INSN_ID(niobj, send)) {
niobj = niobj->next;
unsigned int flag = vm_ci_flag((const struct rb_callinfo *)OPERAND_AT(niobj, 0));

if ((flag & VM_CALL_ARGS_SPLAT) && (flag & VM_CALL_KW_SPLAT) &&
(flag & VM_CALL_KW_SPLAT_MUT) && !(flag & VM_CALL_ARGS_BLOCKARG)) {
OPERAND_AT(iobj, 0) = Qfalse;
}
}
}
}

Expand Down

0 comments on commit 5e33f2b

Please sign in to comment.