mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not recompute length
We can get a speed gain by moving the length calculation and assignment out of the loop.
This commit is contained in:
parent
cc81cd359c
commit
897c377bad
1 changed files with 2 additions and 2 deletions
|
@ -140,6 +140,8 @@ module ActiveRecord
|
||||||
# We freeze the strings to prevent them getting duped when
|
# We freeze the strings to prevent them getting duped when
|
||||||
# used as keys in ActiveRecord::Base's @attributes hash
|
# used as keys in ActiveRecord::Base's @attributes hash
|
||||||
columns = @columns.map(&:-@)
|
columns = @columns.map(&:-@)
|
||||||
|
length = columns.length
|
||||||
|
|
||||||
@rows.map { |row|
|
@rows.map { |row|
|
||||||
# In the past we used Hash[columns.zip(row)]
|
# In the past we used Hash[columns.zip(row)]
|
||||||
# though elegant, the verbose way is much more efficient
|
# though elegant, the verbose way is much more efficient
|
||||||
|
@ -148,8 +150,6 @@ module ActiveRecord
|
||||||
hash = {}
|
hash = {}
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
length = columns.length
|
|
||||||
|
|
||||||
while index < length
|
while index < length
|
||||||
hash[columns[index]] = row[index]
|
hash[columns[index]] = row[index]
|
||||||
index += 1
|
index += 1
|
||||||
|
|
Loading…
Reference in a new issue