From 2ada56f858177510c5003b906041669152cce2bb Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 16 Nov 2010 23:09:15 -0800 Subject: [PATCH] Avoid N << method calls in #import_without_validations_or_callbacks by chaining #map (is simpler, should be more performant, AFAIK) --- lib/activerecord-import/import.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index e1290e9..fbc8b85 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -264,12 +264,11 @@ class ActiveRecord::Base insert_statements, values = [], [] number_inserted = 0 array_of_attributes.each do |arr| - my_values = [] - arr.each_with_index do |val,j| + my_values = arr.each_with_index.map do |val,j| if !sequence_name.blank? && column_names[j] == primary_key && val.nil? - my_values << connection.next_value_for_sequence(sequence_name) + connection.next_value_for_sequence(sequence_name) else - my_values << connection.quote( val, columns[j] ) + connection.quote( val, columns[j] ) end end insert_statements << "INSERT INTO #{quoted_table_name} #{columns_sql} VALUES(" + my_values.join( ',' ) + ")"