summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
authorJeremy Evans <[email protected]>2024-07-12 13:28:53 -0700
committerJeremy Evans <[email protected]>2024-07-18 22:17:21 -0700
commit94e7d2664388039fc8c2f6a063017cae22193fa3 (patch)
tree16eac64dc63bc08a75563fbc71ed1c0e1f1ec99f /test/ruby
parent2c79a7641ffbd5da7d5215a218e0d6866f061423 (diff)
Avoid array allocation for f(*empty_ary, **hash) when def f(x)
This avoids an array allocation when calling a method that does not accept a positional splat or keywords with both a positional splat and keywords. Previously, Ruby would dup the positional splat to append the keyword splat to it. Then it would flatten the dupped positional splat array to the VM stack. This flattens the given positional splat to the VM stack, then adds the keyword splat hash after the last positional splat element on the VM stack, avoiding the need to modify the positional splat array.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11161
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_allocation.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb
index 42a3cdeead..3f83b98470 100644
--- a/test/ruby/test_allocation.rb
+++ b/test/ruby/test_allocation.rb
@@ -123,8 +123,7 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(0, 0, "required(*r2k_empty_array1#{block})")
check_allocations(0, 1, "required(*r2k_array#{block})")
- # Currently allocates 1 array unnecessarily
- check_allocations(1, 1, "required(*empty_array, **hash1, **empty_hash#{block})")
+ check_allocations(0, 1, "required(*empty_array, **hash1, **empty_hash#{block})")
RUBY
end
@@ -148,8 +147,7 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(0, 0, "optional(*r2k_empty_array1#{block})")
check_allocations(0, 1, "optional(*r2k_array#{block})")
- # Currently allocates 1 array unnecessarily
- check_allocations(1, 1, "optional(*empty_array, **hash1, **empty_hash#{block})")
+ check_allocations(0, 1, "optional(*empty_array, **hash1, **empty_hash#{block})")
RUBY
end