From 73371450c31ed6341858c6520b3cd2d3d451806e Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 25 Jan 2024 12:25:42 -0800 Subject: [PATCH] Avoid 1-2 array allocations for zsuper calls with post arguments These previously resulted in 2 array allocations, one for newarray and one for concatarray. This replaces newarray and concatarray with pushtoarray, and changes splatarray false to splatarray true, which reduces it to 1 array allocation, in splatarray true. This also sets VM_CALL_ARGS_SPLAT_MUT, so if the super method accepts a positional splat, this will avoid an additional array allocation on the callee side. --- compile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compile.c b/compile.c index 05e4091172..36cc973f3f 100644 --- a/compile.c +++ b/compile.c @@ -9520,7 +9520,7 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i /* rest argument */ int idx = local_body->local_table_size - local_body->param.rest_start; ADD_GETLOCAL(args, node, idx, lvar_level); - ADD_INSN1(args, node, splatarray, Qfalse); + ADD_INSN1(args, node, splatarray, local_body->param.flags.has_post ? Qtrue : Qfalse); argc = local_body->param.rest_start + 1; flag |= VM_CALL_ARGS_SPLAT; @@ -9529,6 +9529,7 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i /* post arguments */ int post_len = local_body->param.post_num; int post_start = local_body->param.post_start; + flag |= VM_CALL_ARGS_SPLAT_MUT; if (local_body->param.flags.has_rest) { int j; @@ -9536,8 +9537,7 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i int idx = local_body->local_table_size - (post_start + j); ADD_GETLOCAL(args, node, idx, lvar_level); } - ADD_INSN1(args, node, newarray, INT2FIX(j)); - ADD_INSN (args, node, concatarray); + ADD_INSN1(args, node, pushtoarray, INT2FIX(j)); /* argc is settled at above */ } else {