Skip to content

Commit b87e1e6

Browse files
committed
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.
1 parent 34ea0a5 commit b87e1e6

File tree

1 file changed

+6
-3
lines changed
  • activesupport/lib/active_support

1 file changed

+6
-3
lines changed

activesupport/lib/active_support/cache.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,12 @@ def normalize_key(key, options = nil)
945945
#
946946
# namespace_key 'foo', namespace: -> { 'cache' }
947947
# # => 'cache:foo'
948-
def namespace_key(key, options = nil)
949-
options = merged_options(options)
950-
namespace = options[:namespace]
948+
def namespace_key(key, call_options = nil)
949+
namespace = if call_options&.key?(:namespace)
950+
call_options[:namespace]
951+
else
952+
options[:namespace]
953+
end
951954

952955
if namespace.respond_to?(:call)
953956
namespace = namespace.call

0 commit comments

Comments
 (0)