aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-12 17:49:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-12 17:49:12 -0700
commit79e9f4a3183064aa5486cda0e7cbddfea6e08c33 (patch)
tree2f5b73ca98ed3b8f17db7f3f6a1bb06a84d885a4 /activerecord
parent8521cdf03d2b9761f21b593e10a31ca96d05092c (diff)
downloadrails-79e9f4a3183064aa5486cda0e7cbddfea6e08c33.tar.gz
rails-79e9f4a3183064aa5486cda0e7cbddfea6e08c33.tar.bz2
rails-79e9f4a3183064aa5486cda0e7cbddfea6e08c33.zip
PostgreSQLAdapter#select_raw use each_with_index to avoid multiple array lookups
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 1429f44ff3..f4756ed18d 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -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