aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_set/builder.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-14 10:45:53 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-14 14:30:39 -0700
commit70d1b5a7f8e25b077168deaf592e0e58c3f2bdd1 (patch)
tree1f74f87d45b6f539f8378a44652a9571bb47bfd0 /activerecord/lib/active_record/attribute_set/builder.rb
parent114e9f2bdf9327ebadb1fc72400c1ef80c3f6c3b (diff)
downloadrails-70d1b5a7f8e25b077168deaf592e0e58c3f2bdd1.tar.gz
rails-70d1b5a7f8e25b077168deaf592e0e58c3f2bdd1.tar.bz2
rails-70d1b5a7f8e25b077168deaf592e0e58c3f2bdd1.zip
Revert "Improve performance of AR object instantiation"
This reverts commit 8fee923888192a658d8823b31e77ed0683dfd665. Conflicts: activerecord/lib/active_record/attribute_set/builder.rb This solution sucks, and is hard to actually apply across the board. Going to try other solutions
Diffstat (limited to 'activerecord/lib/active_record/attribute_set/builder.rb')
-rw-r--r--activerecord/lib/active_record/attribute_set/builder.rb21
1 files changed, 3 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb
index 0a62c68bfb..d4a787f2fe 100644
--- a/activerecord/lib/active_record/attribute_set/builder.rb
+++ b/activerecord/lib/active_record/attribute_set/builder.rb
@@ -8,33 +8,18 @@ module ActiveRecord
end
def build_from_database(values = {}, additional_types = {})
- build_from_database_pairs(values.keys, values.values, additional_types)
- end
-
- def build_from_database_pairs(columns, values, additional_types)
- attributes = build_attributes_from_values(columns, values, additional_types)
+ attributes = build_attributes_from_values(values, additional_types)
add_uninitialized_attributes(attributes)
AttributeSet.new(attributes)
end
private
- def build_attributes_from_values(columns, values, additional_types)
- # We are performing manual iteration here as this method is a performance
- # hotspot
- hash = {}
- index = 0
- length = columns.length
-
- while index < length
- name = columns[index]
- value = values[index]
+ def build_attributes_from_values(values, additional_types)
+ values.each_with_object({}) do |(name, value), hash|
type = additional_types.fetch(name, types[name])
hash[name] = Attribute.from_database(name, value, type)
- index += 1
end
-
- hash
end
def add_uninitialized_attributes(attributes)