mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
Use yield instead of to_proc in Hash#merge
This is functionally equivalent. However, the previous behavior resulted in the block being materialized as a proc which is quite expensive, both during materialization as well as when calling it. By using `block_given?`, we can avoid this materialization.
This commit is contained in:
parent
16cb49c3f1
commit
0edcce37c7
@ -276,8 +276,14 @@ module Rackstash
|
||||
# and `force` is `true`
|
||||
# @return [Rackstash::Fields::Hash] a new hash containing the merged
|
||||
# key-value pairs
|
||||
def merge(hash, force: true, scope: nil, &block)
|
||||
dup.merge!(hash, force: force, scope: scope, &block)
|
||||
def merge(hash, force: true, scope: nil)
|
||||
if block_given?
|
||||
dup.merge!(hash, force: force, scope: scope) { |key, old_val, new_val|
|
||||
yield key, old_val, new_val
|
||||
}
|
||||
else
|
||||
dup.merge!(hash, force: force, scope: scope)
|
||||
end
|
||||
end
|
||||
|
||||
# Adds the contents of `hash` to `self`. `hash` is normalized before being
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user