1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #40171 from vinistock/reduce_allocations_in_cache_methods

Reduce allocations in expanded_version and expanded_key
This commit is contained in:
Kasper Timm Hansen 2020-09-05 14:32:36 +02:00 committed by GitHub
commit 0e5f9a0a42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -617,13 +617,7 @@ module ActiveSupport
# Deletes multiples entries in the cache implementation. Subclasses MAY
# implement this method.
def delete_multi_entries(entries, **options)
entries.inject(0) do |sum, key|
if delete_entry(key, **options)
sum + 1
else
sum
end
end
entries.count { |key| delete_entry(key, **options) }
end
# Merges the default options with ones specific to a method call.
@ -687,7 +681,7 @@ module ActiveSupport
expanded_key(key.first)
end
when Hash
key.collect { |k, v| "#{k}=#{v}" }.sort
key.collect { |k, v| "#{k}=#{v}" }.sort!
else
key
end.to_param
@ -700,7 +694,7 @@ module ActiveSupport
def expanded_version(key)
case
when key.respond_to?(:cache_version) then key.cache_version.to_param
when key.is_a?(Array) then key.map { |element| expanded_version(element) }.compact.to_param
when key.is_a?(Array) then key.map { |element| expanded_version(element) }.tap(&:compact!).to_param
when key.respond_to?(:to_a) then expanded_version(key.to_a)
end
end