aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorLawrence Pit <lawrence.pit@gmail.com>2011-07-15 09:58:46 +1000
committerLawrence Pit <lawrence.pit@gmail.com>2011-07-15 09:58:46 +1000
commitf04c5d640d5703a66193690d1b5948f9f04d4018 (patch)
tree3526eca3cc017cc401feb7d4135675ea4ec4e942 /activemodel
parentf88e9d83f13c7d29120696d7e568fae1efea67f4 (diff)
downloadrails-f04c5d640d5703a66193690d1b5948f9f04d4018.tar.gz
rails-f04c5d640d5703a66193690d1b5948f9f04d4018.tar.bz2
rails-f04c5d640d5703a66193690d1b5948f9f04d4018.zip
Optimization of ActiveModel's match_attribute_method?
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 6ee5e04267..bb5c511a5e 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -410,13 +410,16 @@ module ActiveModel
private
# Returns a struct representing the matching attribute method.
# The struct's attributes are prefix, base and suffix.
+ @@match_attribute_method_cache = {}
def match_attribute_method?(method_name)
+ cache = @@match_attribute_method_cache[self.class] ||= {}
+ return cache[method_name] if cache.key?(method_name)
self.class.attribute_method_matchers.each do |method|
if (match = method.match(method_name)) && attribute_method?(match.attr_name)
- return match
+ return cache[method_name] = match
end
end
- nil
+ cache[method_name] = nil
end
# prevent method_missing from calling private methods with #send