aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-04-27 20:44:08 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-04-27 20:44:09 -0300
commit9d1f6edbe0aa6f95f55464136e39fb4e2e4643f2 (patch)
tree80c97030e7e28a96387eab6659fb84e8dd484f8c /activemodel/lib/active_model
parent3e8d88f7da5226b6dd4e3aee87a84d99d668a652 (diff)
downloadrails-9d1f6edbe0aa6f95f55464136e39fb4e2e4643f2.tar.gz
rails-9d1f6edbe0aa6f95f55464136e39fb4e2e4643f2.tar.bz2
rails-9d1f6edbe0aa6f95f55464136e39fb4e2e4643f2.zip
Return earlier if attribute already changed in *_will_change! methods
Avoid obtaining the value and duplicating it when possible.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/dirty.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index d327913824..7f7fb90d87 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -151,13 +151,15 @@ module ActiveModel
# Handle <tt>*_will_change!</tt> for +method_missing+.
def attribute_will_change!(attr)
+ return if attribute_changed?(attr)
+
begin
value = __send__(attr)
value = value.duplicable? ? value.clone : value
rescue TypeError, NoMethodError
end
- changed_attributes[attr] = value unless changed_attributes.include?(attr)
+ changed_attributes[attr] = value
end
# Handle <tt>reset_*!</tt> for +method_missing+.