Permalink
Browse files

PostgreSQLAdapter#select_raw use each_with_index to avoid multiple ar…

…ray lookups
  • Loading branch information...
tenderlove committed Jul 13, 2010
1 parent 8521cdf commit 79e9f4a3183064aa5486cda0e7cbddfea6e08c33
Showing with 5 additions and 5 deletions.
  1. +5 −5 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -952,7 +952,7 @@ def select_raw(sql, name = nil)
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 @@ def select_raw(sql, name = nil)
# 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

0 comments on commit 79e9f4a

Please sign in to comment.