aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorLawrence Pit <lawrence.pit@gmail.com>2011-07-17 14:51:34 +1000
committerLawrence Pit <lawrence.pit@gmail.com>2011-07-17 14:51:34 +1000
commit52a096275a32c0c5d5125280f144e1e0d893d1f3 (patch)
tree5dab9eb706947bc21ac1e91f4d1b17abc2209447 /activemodel/lib
parentc3dd4c653d0a83b3fbb5c05eb93ee824eb66c944 (diff)
downloadrails-52a096275a32c0c5d5125280f144e1e0d893d1f3.tar.gz
rails-52a096275a32c0c5d5125280f144e1e0d893d1f3.tar.bz2
rails-52a096275a32c0c5d5125280f144e1e0d893d1f3.zip
Made attribute_method_matchers_cache private + doc
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 15abab87d7..bdc0eb4a0d 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -61,9 +61,6 @@ module ActiveModel
included do
class_attribute :attribute_method_matchers, :instance_writer => false
self.attribute_method_matchers = []
-
- class_attribute :attribute_method_matchers_cache, :instance_writer => false
- self.attribute_method_matchers_cache = {}
end
module ClassMethods
@@ -343,6 +340,19 @@ module ActiveModel
end
private
+ # The methods +method_missing+ and +respond_to?+ of this module are
+ # invoked often in a typical rails, both of which invoke the method
+ # +match_attribute_method?+. The latter method iterates through an
+ # array doing regular expression matches, which results in a lot of
+ # object creations. Most of the times it returns a +nil+ match. As the
+ # match result is always the same given a +method_name+, this cache is
+ # used to alleviate the GC, which ultimately also speeds up the app
+ # significantly (in our case our test suite finishes 10% faster with
+ # this cache).
+ def attribute_method_matchers_cache
+ @attribute_method_matchers_cache ||= {}
+ end
+
def attribute_method_matcher(method_name)
if attribute_method_matchers_cache.key?(method_name)
attribute_method_matchers_cache[method_name]