diff options
author | Jeremy Evans <[email protected]> | 2024-05-11 12:12:52 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2024-05-21 05:33:57 +0900 |
commit | 2433b57b6a3a6f8e65f61c27d707e1c7f5407986 (patch) | |
tree | 1c296abcc567a614be6e788ec575fbc2fd3e2e53 /vm_args.c | |
parent | f021bcdbbe69d324b36c03dab4d2347608658b86 (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.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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 |