summaryrefslogtreecommitdiff
path: root/vm_args.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-05-14 17:03:46 -0700
committerJeremy Evans <[email protected]>2024-05-21 05:33:57 +0900
commit86cf074fa1dcf73846e094775414d661e47dfc76 (patch)
tree3211bf56a224daae8d4dd567c8529a4affdbd306 /vm_args.c
parent2433b57b6a3a6f8e65f61c27d707e1c7f5407986 (diff)
Avoid array allocation for empty ruby2_keywords flagged keyword hash
If the method being called does not have a positional splat parameter, there is no point in allocating the array, as decrementing given_argc is sufficient to ensure the empty keyword hash is not considered an argument, assuming that we are calling a method/lambda and not a regular proc.
Diffstat (limited to 'vm_args.c')
-rw-r--r--vm_args.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/vm_args.c b/vm_args.c
index 1db62dc7e2..0c1a26cfad 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -693,8 +693,11 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
args->rest_dupped = false;
if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
- arg_rest_dup(args);
- rb_ary_pop(args->rest);
+ if (ISEQ_BODY(iseq)->param.flags.has_rest || arg_setup_type != arg_setup_method) {
+ // Only duplicate/modify splat array if it will be used
+ arg_rest_dup(args);
+ rb_ary_pop(args->rest);
+ }
given_argc--;
kw_flag &= ~(VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
}