summaryrefslogtreecommitdiff
path: root/vm_args.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-05-11 12:12:52 -0700
committerJeremy Evans <[email protected]>2024-05-21 05:33:57 +0900
commit2433b57b6a3a6f8e65f61c27d707e1c7f5407986 (patch)
tree1c296abcc567a614be6e788ec575fbc2fd3e2e53 /vm_args.c
parentf021bcdbbe69d324b36c03dab4d2347608658b86 (diff)
Avoid hash allocation for empty ruby2_keywords flagged keyword hash
If the method being called does not have a keyword splat parameter, there is no point in allocating the hash, because the hash will be unused (as empty keyword hashes are ignored).
Diffstat (limited to 'vm_args.c')
-rw-r--r--vm_args.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/vm_args.c b/vm_args.c
index 1a78e96776..1db62dc7e2 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -684,7 +684,9 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
// def f(**kw); a = [..., kw]; g(*a)
splat_flagged_keyword_hash = rest_last;
- rest_last = rb_hash_dup(rest_last);
+ if (!RHASH_EMPTY_P(rest_last) || (ISEQ_BODY(iseq)->param.flags.has_kwrest)) {
+ rest_last = rb_hash_dup(rest_last);
+ }
kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
// Unset rest_dupped set by anon_rest as we may need to modify splat in this case