From f171bc64a2fcb321284b10c0c454f16569505439 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 29 Jul 2010 14:55:57 -0700 Subject: PERF: avoiding splat args and reducing function calls --- activerecord/lib/active_record/relation/query_methods.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 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 0593897fa5..05962f409f 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -47,9 +47,9 @@ module ActiveRecord clone.tap {|r| r.joins_values += args if args.present? } end - def where(*args) - value = build_where(*args) - clone.tap {|r| r.where_values += Array.wrap(value) if value.present? } + def where(opts, other = nil) + value = build_where(opts, other) + value ? clone : clone.tap {|r| r.where_values += Array.wrap(value) } end def having(*args) @@ -166,13 +166,10 @@ module ActiveRecord arel end - def build_where(*args) - return if args.blank? - - opts = args.first + def build_where(opts, other = nil) case opts when String, Array - @klass.send(:sanitize_sql, args.size > 1 ? args : opts) + @klass.send(:sanitize_sql, other ? [opts, other] : opts) when Hash attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts) PredicateBuilder.new(table.engine).build_from_hash(attributes, table) -- cgit v1.2.3