mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Avoid allocation when passing no keywords to anonymous kwrest methods
Thanks to the new semantics from [ruby-core:115808], `**nil` is now
equivalent to `**{}`. Since the only thing one could do with anonymous
keyword rest parameter is to delegate it with `**`, nil is just as good
as an empty hash. Using nil avoids allocating an empty hash.
This is particularly important for `...` methods since they now use
`**kwrest` under the hood after 4f77d8d328
. Most calls don't pass
keywords.
Comparison:
fw_no_kw
post: 9816800.9 i/s
pre: 8570297.0 i/s - 1.15x slower
This commit is contained in:
parent
4e481c772e
commit
e4272fd292
2 changed files with 8 additions and 3 deletions
|
@ -7,6 +7,7 @@ prelude: |
|
|||
def anon_fw_to_named(*, **) named_arg_kw_splat(*, **) end
|
||||
def fw_to_named(...) named_arg_kw_splat(...) end
|
||||
def fw_to_anon_to_named(...) anon_fw_to_named(...) end
|
||||
def fw_no_kw(...) named_arg_splat(...) end
|
||||
a = [1]
|
||||
kw = {y: 1}
|
||||
benchmark:
|
||||
|
@ -23,3 +24,4 @@ benchmark:
|
|||
fw_to_named_no_splat: "fw_to_named(1, y: 1)"
|
||||
fw_to_anon_to_named_splat: "fw_to_anon_to_named(*a, **kw)"
|
||||
fw_to_anon_to_named_no_splat: "fw_to_anon_to_named(1, y: 1)"
|
||||
fw_no_kw: "fw_no_kw(1, 2)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue