Skip to content
This repository
Browse code

ActiveRecord#attributes optimization: minimize objects created

  • Loading branch information...
commit 6e4a064256331f21b3b3107e2349f7e7adc6d8e6 1 parent 8475cdd
Tieg Zaharia authored June 09, 2012
4  activerecord/lib/active_record/attribute_methods.rb
@@ -181,7 +181,9 @@ def attribute_names
181 181
 
182 182
     # Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
183 183
     def attributes
184  
-      Hash[@attributes.map { |name, _| [name, read_attribute(name)] }]
  184
+      attrs = {}
  185
+      attribute_names.each { |name| attrs[name] = read_attribute(name) }
  186
+      attrs
185 187
     end
186 188
 
187 189
     # Returns an <tt>#inspect</tt>-like string for the value of the

0 notes on commit 6e4a064

Please sign in to comment.
Something went wrong with that request. Please try again.