Permalink
Browse files

PERF: avoiding splat args and reducing function calls

  • Loading branch information...
1 parent aa054c3 commit f171bc64a2fcb321284b10c0c454f16569505439 @tenderlove tenderlove committed Jul 29, 2010
Showing with 5 additions and 8 deletions.
  1. +5 −8 activerecord/lib/active_record/relation/query_methods.rb
@@ -47,9 +47,9 @@ def joins(*args)
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 @@ def build_arel
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)

0 comments on commit f171bc6

Please sign in to comment.