From 6e4a064256331f21b3b3107e2349f7e7adc6d8e6 Mon Sep 17 00:00:00 2001 From: Tieg Zaharia Date: Sat, 9 Jun 2012 00:42:55 -0400 Subject: ActiveRecord#attributes optimization: minimize objects created --- activerecord/lib/active_record/attribute_methods.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 06b66b5195..7fc3b2bb5d 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -181,7 +181,9 @@ module ActiveRecord # Returns a hash of all the attributes with their names as keys and the values of the attributes as values. def attributes - Hash[@attributes.map { |name, _| [name, read_attribute(name)] }] + attrs = {} + attribute_names.each { |name| attrs[name] = read_attribute(name) } + attrs end # Returns an #inspect-like string for the value of the -- cgit v1.2.3