mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
PostgreSQLAdapter#select_raw use each_with_index to avoid multiple array lookups
This commit is contained in:
@@ -952,7 +952,7 @@ module ActiveRecord
|
||||
fields = res.fields
|
||||
rows = results.map do |row|
|
||||
hashed_row = {}
|
||||
row.each_index do |cell_index|
|
||||
row.each_with_index do |cell, cell_index|
|
||||
# If this is a money type column and there are any currency symbols,
|
||||
# then strip them off. Indeed it would be prettier to do this in
|
||||
# PostgreSQLColumn.string_to_decimal but would break form input
|
||||
@@ -962,15 +962,15 @@ module ActiveRecord
|
||||
# cases to consider (note the decimal separators):
|
||||
# (1) $12,345,678.12
|
||||
# (2) $12.345.678,12
|
||||
case column = row[cell_index]
|
||||
case cell
|
||||
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
|
||||
row[cell_index] = column.gsub(/[^-\d\.]/, '')
|
||||
row[cell_index] = cell.gsub(/[^-\d\.]/, '')
|
||||
when /^-?\D+[\d\.]+,\d{2}$/ # (2)
|
||||
row[cell_index] = column.gsub(/[^-\d,]/, '').sub(/,/, '.')
|
||||
row[cell_index] = cell.gsub(/[^-\d,]/, '').sub(/,/, '.')
|
||||
end
|
||||
end
|
||||
|
||||
hashed_row[fields[cell_index]] = column
|
||||
hashed_row[fields[cell_index]] = cell
|
||||
end
|
||||
row
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user