Eliminate array allocation for f(1, *a)
Due to how the compiler works, while f(*a) does not allocate an array f(1, *a) does. This is possible to fix in the compiler, but the change is much more complex. This attempts to fix the issue in a simpler way using the peephole optimizer. Eliminating this array allocation is safe, since just as in the f(*a) case, nothing else on the caller side can modify the array.
This commit is contained in:
parent
41b299d639
commit
40a2afd08f
21
compile.c
21
compile.c
@ -3836,6 +3836,27 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_INSN_ID(iobj, splatarray) && OPERAND_AT(iobj, 0) == Qtrue) {
|
||||
LINK_ELEMENT *niobj = &iobj->link;
|
||||
|
||||
/*
|
||||
* Eliminate array allocation for f(1, *a)
|
||||
*
|
||||
* splatarray true
|
||||
* send ARGS_SPLAT and not KW_SPLAT|ARGS_BLOCKARG
|
||||
* =>
|
||||
* splatarray false
|
||||
* 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|VM_CALL_ARGS_BLOCKARG))) {
|
||||
OPERAND_AT(iobj, 0) = Qfalse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return COMPILE_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user