From b2eb3a4c33138336febb2d5576d91021d61c68dd Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 28 Sep 2010 14:32:59 -0400 Subject: [PATCH] performance improvement based on discussion at http://github.com/rails/rails/commit/fbd1d306b95cc2efb6422e12d26d5818a3a42343 Credit goes to all the participants in the discussion --- .../lib/active_record/relation/query_methods.rb | 12 +++--------- 1 files changed, 3 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index b9957c4..241f697 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -282,15 +282,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) -- 1.7.2