diff options
author | Jeremy Evans <[email protected]> | 2024-07-12 15:33:59 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2024-07-18 22:17:21 -0700 |
commit | 6428ce80f0ef85324a4d0a72ffa4c6fa2db37cdd (patch) | |
tree | aac9d7262c4394bb937c6e4f6cd5bdabd7301fd0 /test/ruby | |
parent | 1cc5a64dd87a6a474ec8387083d41a3c6c1c3ca5 (diff) |
Avoid array allocation for f(*r2k_ary) when def f(x)
When calling a method that does not accept a positional splat
parameter with a splatted array with a ruby2_keywords flagged hash,
there is no need to duplicate the splatted array. Previously,
Ruby would duplicate the splatted array and potentially modify
it before flattening it to the VM stack
Use a similar approach as the f(*ary, **hash) optimization,
flattening the splatted array to the VM stack without modifying
it, and make any modifications needed to the VM stack.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11161
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_allocation.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb index 793b041529..60faa44e4f 100644 --- a/test/ruby/test_allocation.rb +++ b/test/ruby/test_allocation.rb @@ -265,7 +265,7 @@ class TestAllocation < Test::Unit::TestCase check_allocations(1, 0, "keyword(*empty_array, *empty_array, **empty_hash#{block})") check_allocations(0, 0, "keyword(*r2k_empty_array#{block})") - check_allocations(1, 0, "keyword(*r2k_array#{block})") + check_allocations(0, 0, "keyword(*r2k_array#{block})") check_allocations(0, 1, "keyword(*empty_array, a: 2, **empty_hash#{block})") check_allocations(0, 1, "keyword(*empty_array, **hash1, **empty_hash#{block})") @@ -291,8 +291,8 @@ class TestAllocation < Test::Unit::TestCase check_allocations(0, 1, "keyword_splat(*empty_array#{block})") check_allocations(1, 1, "keyword_splat(*empty_array, *empty_array, **empty_hash#{block})") - check_allocations(1, 1, "keyword_splat(*r2k_empty_array#{block})") - check_allocations(1, 1, "keyword_splat(*r2k_array#{block})") + check_allocations(0, 1, "keyword_splat(*r2k_empty_array#{block})") + check_allocations(0, 1, "keyword_splat(*r2k_array#{block})") check_allocations(0, 1, "keyword_splat(*empty_array, a: 2, **empty_hash#{block})") check_allocations(0, 1, "keyword_splat(*empty_array, **hash1, **empty_hash#{block})") @@ -318,8 +318,8 @@ class TestAllocation < Test::Unit::TestCase check_allocations(0, 1, "keyword_and_keyword_splat(*empty_array#{block})") check_allocations(1, 1, "keyword_and_keyword_splat(*empty_array, *empty_array, **empty_hash#{block})") - check_allocations(1, 1, "keyword_and_keyword_splat(*r2k_empty_array#{block})") - check_allocations(1, 1, "keyword_and_keyword_splat(*r2k_array#{block})") + check_allocations(0, 1, "keyword_and_keyword_splat(*r2k_empty_array#{block})") + check_allocations(0, 1, "keyword_and_keyword_splat(*r2k_array#{block})") check_allocations(0, 1, "keyword_and_keyword_splat(*empty_array, a: 2, **empty_hash#{block})") check_allocations(0, 1, "keyword_and_keyword_splat(*empty_array, **hash1, **empty_hash#{block})") @@ -359,7 +359,7 @@ class TestAllocation < Test::Unit::TestCase check_allocations(1, 1, "required_and_keyword(*array1, *empty_array, **hash1, **empty_hash#{block})") check_allocations(0, 0, "required_and_keyword(*r2k_empty_array1#{block})") - check_allocations(1, 0, "required_and_keyword(*r2k_array1#{block})") + check_allocations(0, 0, "required_and_keyword(*r2k_array1#{block})") check_allocations(0, 1, "required_and_keyword(1, *empty_array, a: 2, **empty_hash#{block})") check_allocations(0, 1, "required_and_keyword(1, *empty_array, **hash1, **empty_hash#{block})") @@ -446,8 +446,8 @@ class TestAllocation < Test::Unit::TestCase check_allocations(1, 1, "required_and_keyword_splat(*array1, *empty_array, a: 2, **empty_hash#{block})") check_allocations(1, 1, "required_and_keyword_splat(*array1, *empty_array, **hash1, **empty_hash#{block})") - check_allocations(1, 1, "required_and_keyword_splat(*r2k_empty_array1#{block})") - check_allocations(1, 1, "required_and_keyword_splat(*r2k_array1#{block})") + check_allocations(0, 1, "required_and_keyword_splat(*r2k_empty_array1#{block})") + check_allocations(0, 1, "required_and_keyword_splat(*r2k_array1#{block})") check_allocations(0, 1, "required_and_keyword_splat(1, *empty_array, a: 2, **empty_hash#{block})") check_allocations(0, 1, "required_and_keyword_splat(1, *empty_array, **hash1, **empty_hash#{block})") |