aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-12-14 11:12:50 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-12-14 11:12:50 -0800
commit49219293e589093a3ceff9279fd4803271da082d (patch)
treeeda4cbbcf56a41b6dd1b24f5b899b706d2b2cc25 /activemodel/lib/active_model
parentce130ef78cc0ac244db63c1ce52f7eb8b2d8c9d8 (diff)
parent45448a578877f6a753492113d72cc3512a6f1720 (diff)
downloadrails-49219293e589093a3ceff9279fd4803271da082d.tar.gz
rails-49219293e589093a3ceff9279fd4803271da082d.tar.bz2
rails-49219293e589093a3ceff9279fd4803271da082d.zip
Merge pull request #8510 from thedarkone/thread_safety_improvements
Thread safety improvements
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index af11da1351..db5759ada9 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -1,3 +1,4 @@
+require 'thread_safe'
module ActiveModel
# Raised when an attribute is not defined.
@@ -337,17 +338,17 @@ module ActiveModel
# significantly (in our case our test suite finishes 10% faster with
# this cache).
def attribute_method_matchers_cache #:nodoc:
- @attribute_method_matchers_cache ||= {}
+ @attribute_method_matchers_cache ||= ThreadSafe::Cache.new(:initial_capacity => 4)
end
def attribute_method_matcher(method_name) #:nodoc:
- attribute_method_matchers_cache.fetch(method_name) do |name|
+ attribute_method_matchers_cache.compute_if_absent(method_name) do
# Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix
# will match every time.
matchers = attribute_method_matchers.partition(&:plain?).reverse.flatten(1)
match = nil
- matchers.detect { |method| match = method.match(name) }
- attribute_method_matchers_cache[name] = match
+ matchers.detect { |method| match = method.match(method_name) }
+ match
end
end