Eliminate array allocation for f(*a, kw: 1)

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.
This commit is contained in:
Jeremy Evans 2023-11-06 13:03:02 -08:00
parent 95615872e3
commit 5e33f2b0e4

View File

@ -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;
}
}
}
}