Remove hash allocation in Store#namespace_key

Previously, every call to `namespace_key` would merge the options given
with the Store's default options. This unnecessarily allocates a new
hash when all `namespace_key` needs is the `namespace` option.

This commit removes the allocation by simply checking the default
options after checking that the passed options do not contain a
`namespace` key.
This commit is contained in:
Hartley McGuire 2024-09-20 20:09:00 -04:00
parent 34ea0a5dd2
commit b87e1e6163
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
1 changed files with 6 additions and 3 deletions

View File

@ -945,9 +945,12 @@ module ActiveSupport
#
# namespace_key 'foo', namespace: -> { 'cache' }
# # => 'cache:foo'
def namespace_key(key, options = nil)
options = merged_options(options)
namespace = options[:namespace]
def namespace_key(key, call_options = nil)
namespace = if call_options&.key?(:namespace)
call_options[:namespace]
else
options[:namespace]
end
if namespace.respond_to?(:call)
namespace = namespace.call