Skip to content

Commit

Permalink
Merge pull request #12185 from SamSaffron/join_dep
Browse files Browse the repository at this point in the history
Reduce allocations when extracting AR models
  • Loading branch information
rafaelfranca committed Sep 11, 2013
1 parent 843e9c4 commit 463f989
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,20 @@ def column_names_with_alias
end end


def extract_record(row) 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 end


def record_id(row) def record_id(row)
Expand Down

0 comments on commit 463f989

Please sign in to comment.