aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSam <sam.saffron@gmail.com>2013-09-10 12:39:25 +1000
committerSam <sam.saffron@gmail.com>2013-09-11 13:12:21 +1000
commit14b23ee5fbe184187b33909411f3f28b953207d1 (patch)
tree01c5cc6ceda1bdd8226e014199195ffeabfe41c5 /activerecord/lib
parentf20f90f89a9db8cc0e53d31db8d40c3f5c526e44 (diff)
downloadrails-14b23ee5fbe184187b33909411f3f28b953207d1.tar.gz
rails-14b23ee5fbe184187b33909411f3f28b953207d1.tar.bz2
rails-14b23ee5fbe184187b33909411f3f28b953207d1.zip
Reduce allocations when extracting AR models
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_part.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
index b534569063..f70e277c76 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -62,7 +62,19 @@ module ActiveRecord
end
def extract_record(row)
- Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}]
+ # This code is performance critical as it is called per row.
+ # see: https://github.com/rails/rails/pull/12185
+ hash = {}
+
+ index = 0
+ length = column_names_with_alias.length
+ while index < length
+ column_name,alias_name = column_names_with_alias[index]
+ hash[column_name] = row[alias_name]
+ index += 1
+ end
+
+ hash
end
def record_id(row)