aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/lookup_context.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-18 08:23:26 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-18 08:23:26 -0800
commit3239ed48d28f3c0baf4445e6c279107e892b7cab (patch)
treea9860b5c54a42bd16615ae963341229f6c6698a8 /actionview/lib/action_view/lookup_context.rb
parent13c4cc3b5aea02716b7459c0da641438077f5236 (diff)
downloadrails-3239ed48d28f3c0baf4445e6c279107e892b7cab.tar.gz
rails-3239ed48d28f3c0baf4445e6c279107e892b7cab.tar.bz2
rails-3239ed48d28f3c0baf4445e6c279107e892b7cab.zip
move digest cache on to the DetailsKey object
This moves digest calculation cache on to the details key object. Before, the digest cache was a class level ivar, and one of the keys was the hash value of the details key object: https://github.com/rails/rails/blob/13c4cc3b5aea02716b7459c0da641438077f5236/actionview/lib/action_view/digestor.rb#L28 An object's hash value is not unique, so it's possible for this cache key to produce colliding keys with no resolution. This commit move cache on to the details key object itself, so we know that the digests are always unique per details key object.
Diffstat (limited to 'actionview/lib/action_view/lookup_context.rb')
-rw-r--r--actionview/lib/action_view/lookup_context.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb
index 2a1f4378f5..86afedaa2d 100644
--- a/actionview/lib/action_view/lookup_context.rb
+++ b/actionview/lib/action_view/lookup_context.rb
@@ -69,6 +69,18 @@ module ActionView
def self.clear
@details_keys.clear
end
+
+ def self.empty?; @details_keys.empty?; end
+
+ def self.digest_caches
+ @details_keys.values.map(&:digest_cache)
+ end
+
+ attr_reader :digest_cache
+
+ def initialize
+ @digest_cache = Concurrent::Map.new
+ end
end
# Add caching behavior on top of Details.
@@ -194,6 +206,10 @@ module ActionView
self.view_paths = view_paths
end
+ def digest_cache
+ details_key.digest_cache
+ end
+
def initialize_details(target, details)
registered_details.each do |k|
target[k] = details[k] || Accessors::DEFAULT_PROCS[k].call