Slightly more efficient to loop through serialized_attributes than to loop through the changes hash

This commit is contained in:
Tyler Rick 2012-11-06 15:09:44 -08:00
parent ae2350b147
commit 5e2cd92688
1 changed files with 6 additions and 7 deletions

View File

@ -185,14 +185,13 @@ module PaperTrail
# The double negative (reject, !include?) preserves the hash structure of self.changes.
self.changes.reject do |key, value|
!notably_changed.include?(key)
end.tap do |changes_hash|
end.tap do |changes|
# Use serialized value for attributes that are serialized
changes_hash.each do |key, (old_value, new_value)|
if serialized_attributes.include?(key)
# coder.dump(new_value) is the same as @attributes[key].serialized_value
coder = @attributes[key].coder
changes_hash[key] = [coder.dump(old_value),
coder.dump(new_value)]
serialized_attributes.each do |key, coder|
if changes.key?(key)
old_value, new_value = changes[key]
changes[key] = [coder.dump(old_value),
coder.dump(new_value)]
end
end
end