diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-09-11 12:29:09 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-09-11 12:29:09 -0700 |
commit | 919547ccfb0d7be5aeea29abe48837b27136c8da (patch) | |
tree | bc215cf23376805bb312e7cebed087e8c1e51ea1 | |
parent | 2a0f2603d18064a1997b5c31a07b0e17edb1fbf5 (diff) | |
parent | 14b23ee5fbe184187b33909411f3f28b953207d1 (diff) | |
download | rails-919547ccfb0d7be5aeea29abe48837b27136c8da.tar.gz rails-919547ccfb0d7be5aeea29abe48837b27136c8da.tar.bz2 rails-919547ccfb0d7be5aeea29abe48837b27136c8da.zip |
Merge pull request #12185 from SamSaffron/join_dep
Reduce allocations when extracting AR models
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_part.rb | 14 |
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) |