aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-11-06 13:17:49 -0800
committerJeremy Evans <code@jeremyevans.net>2023-12-07 11:27:55 -0800
commitaa808204bb3b84ad37e2c4722f9d00e07ab8f281 (patch)
treee90cab8e11d7884ef495b19cae49662f458c00e5 /compile.c
parent5e33f2b0e4c262ed0c7e524b11d020438c41f532 (diff)
downloadruby-aa808204bb3b84ad37e2c4722f9d00e07ab8f281.tar.gz
Eliminate array allocation for f(*a, kw: 1, &lvar) and f(*a, kw: 1, &@iv)
Similar to the previous commit, but this handles the block pass case.
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index f6236ebcc5..27f64febe8 100644
--- a/compile.c
+++ b/compile.c
@@ -3940,6 +3940,32 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
OPERAND_AT(iobj, 0) = Qfalse;
}
}
+ else if (IS_NEXT_INSN_ID(niobj, getlocal) || IS_NEXT_INSN_ID(niobj, getinstancevariable)) {
+ niobj = niobj->next;
+
+ /*
+ * Eliminate array allocation for f(*a, kw: 1, &lvar) and f(*a, kw: 1, &@iv)
+ *
+ * splatarray true
+ * duphash
+ * getlocal / getinstancevariable
+ * send ARGS_SPLAT|KW_SPLAT|KW_SPLAT_MUT|ARGS_BLOCKARG
+ * =>
+ * splatarray false
+ * duphash
+ * getlocal / getinstancevariable
+ * 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;
+ }
+ }
+ }
}
}