ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Avoid a hash allocation when keyword splatting empty hash when calling ruby2_keywords method

Open jeremyevans opened this issue 1 month ago • 0 comments

Treat this similar to keyword splatting nil, using goto ignore. However, keep previous behavior if the method accepts a keyword splat, to avoid double hash allocation.

This also can avoid an array allocation when calling a method that doesn't have any splat parameters but supports literal keyword parameters, because ignore_keyword_hash_p was not ignoring the keyword hash in that case.

This change doesn't remove the empty ruby2_keywords hash from the array, which caused an assertion failure if the method being called accepted keywords in some cases. Modify the assertion to handle this case. An alternative approach would add a flag to the args struct so the args_argc calculation could handle this case and report the correct argc, but such an approach would likely be slower.

jeremyevans avatar Jun 19 '24 18:06 jeremyevans