1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve performance of grouping_any/grouping_all

This commit is contained in:
Ernie Miller 2011-04-19 00:05:19 +08:00 committed by Aaron Patterson
parent fc353baa80
commit 3e3d4d1979

View file

@ -163,21 +163,14 @@ module Arel
private
def grouping_any method_id, others
others = others.dup
first = send method_id, others.shift
Nodes::Grouping.new others.inject(first) { |memo,expr|
Nodes::Or.new(memo, send(method_id, expr))
nodes = others.map {|expr| send(method_id, expr)}
Nodes::Grouping.new nodes.inject { |memo,node|
Nodes::Or.new(memo, node)
}
end
def grouping_all method_id, others
others = others.dup
first = send method_id, others.shift
Nodes::Grouping.new others.inject(first) { |memo,expr|
Nodes::And.new([memo, send(method_id, expr)])
}
Nodes::Grouping.new Nodes::And.new(others.map {|expr| send(method_id, expr)})
end
end
end