From b87e1e6163d37e9793ef431e44172f91e226af8c Mon Sep 17 00:00:00 2001 From: Hartley McGuire Date: Fri, 20 Sep 2024 20:09:00 -0400 Subject: [PATCH] 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. --- activesupport/lib/active_support/cache.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 74ba20c4b06..2c42bb87072 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -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