Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed Ruby 1.8 performance regression for Nodes::In and Nodes::NotIn …

…queries with very wide ranges that was caused by using Range#min and Range#max rather than Range#begin and Range#end. Ruby 1.8 uses Enumerable#min and Enumerable#max in Ranges, which calls to_a internally. It is not necessary to enumerate the range in order to construct the predicates. At the same time, an off-by-one error (failing test) with exclusive-end Ranges in Nodes::NotIn queries was fixed.
  • Loading branch information...
commit 9244e2ddbd5dbfb32f892bdfc23a928aa06999a5 1 parent 35f25f6
Rolf Timmermans authored tenderlove committed
Showing with 7 additions and 7 deletions.
  1. +7 −7 lib/arel/predications.rb
View
14 lib/arel/predications.rb
@@ -30,11 +30,11 @@ def in other
Nodes::In.new self, other.to_a.map { |x| x.id }
when Range
if other.exclude_end?
- left = Nodes::GreaterThanOrEqual.new(self, other.min)
- right = Nodes::LessThan.new(self, other.max + 1)
+ left = Nodes::GreaterThanOrEqual.new(self, other.begin)
+ right = Nodes::LessThan.new(self, other.end)
Nodes::And.new left, right
else
- Nodes::Between.new(self, Nodes::And.new(other.min, other.max))
+ Nodes::Between.new(self, Nodes::And.new(other.begin, other.end))
end
else
Nodes::In.new self, other
@@ -55,12 +55,12 @@ def not_in other
Nodes::NotIn.new self, other.to_a.map { |x| x.id }
when Range
if other.exclude_end?
- left = Nodes::LessThan.new(self, other.min)
- right = Nodes::GreaterThanOrEqual.new(self, other.max)
+ left = Nodes::LessThan.new(self, other.begin)
+ right = Nodes::GreaterThanOrEqual.new(self, other.end)
Nodes::Or.new left, right
else
- left = Nodes::LessThan.new(self, other.min)
- right = Nodes::GreaterThan.new(self, other.max)
+ left = Nodes::LessThan.new(self, other.begin)
+ right = Nodes::GreaterThan.new(self, other.end)
Nodes::Or.new left, right
end
else
Please sign in to comment.
Something went wrong with that request. Please try again.