From 3f16103daf330a067454dd2ae324d8d238ac5ba3 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 28 Sep 2010 14:32:59 -0400 Subject: performance improvement based on discussion at http://github.com/rails/rails/commit/fbd1d306b95cc2efb6422e12d26d5818a3a42343 Credit goes to all the participants in the discussion --- activerecord/lib/active_record/relation/query_methods.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record/relation/query_methods.rb') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index b25388c0e8..e2b1330c24 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -280,15 +280,9 @@ module ActiveRecord end def reverse_sql_order(order_query) - order_query.join(', ').split(',').collect { |s| - if s.match(/\s(asc|ASC)$/) - s.gsub(/\s(asc|ASC)$/, ' DESC') - elsif s.match(/\s(desc|DESC)$/) - s.gsub(/\s(desc|DESC)$/, ' ASC') - else - s + ' DESC' - end - } + order_query.join(', ').split(',').collect do |s| + s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') + end end def array_of_strings?(o) -- cgit v1.2.3