aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2018-08-30 09:57:01 -0500
committerschneems <richard.schneeman+foo@gmail.com>2018-08-30 09:57:58 -0500
commit897c377bad1cb5aa0c35e86c677e6b51cd3da2ac (patch)
tree27b6985d250650a9f3cb33efc41709f5fd53c14f /activerecord/lib/active_record/result.rb
parentcc81cd359c82bfba27388237a455fc345dce3c9f (diff)
downloadrails-897c377bad1cb5aa0c35e86c677e6b51cd3da2ac.tar.gz
rails-897c377bad1cb5aa0c35e86c677e6b51cd3da2ac.tar.bz2
rails-897c377bad1cb5aa0c35e86c677e6b51cd3da2ac.zip
Do not recompute length
We can get a speed gain by moving the length calculation and assignment out of the loop.
Diffstat (limited to 'activerecord/lib/active_record/result.rb')
-rw-r--r--activerecord/lib/active_record/result.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index 7f1c2fd7eb..3b2556b1c8 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -140,6 +140,8 @@ module ActiveRecord
# We freeze the strings to prevent them getting duped when
# used as keys in ActiveRecord::Base's @attributes hash
columns = @columns.map(&:-@)
+ length = columns.length
+
@rows.map { |row|
# In the past we used Hash[columns.zip(row)]
# though elegant, the verbose way is much more efficient
@@ -148,8 +150,6 @@ module ActiveRecord
hash = {}
index = 0
- length = columns.length
-
while index < length
hash[columns[index]] = row[index]
index += 1