aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorRolf Timmermans <r.timmermans@voormedia.com>2010-11-17 22:23:33 +0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-18 00:37:16 +0800
commit9244e2ddbd5dbfb32f892bdfc23a928aa06999a5 (patch)
tree5588197d71722fd93430d1f0fbb027e0f4c45724 /lib/arel
parent35f25f643cca00c192d971234942d5a0d0e07cc0 (diff)
downloadrails-9244e2ddbd5dbfb32f892bdfc23a928aa06999a5.tar.gz
rails-9244e2ddbd5dbfb32f892bdfc23a928aa06999a5.tar.bz2
rails-9244e2ddbd5dbfb32f892bdfc23a928aa06999a5.zip
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.
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/predications.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb
index 8a8960f0b1..03cbb7aa3f 100644
--- a/lib/arel/predications.rb
+++ b/lib/arel/predications.rb
@@ -30,11 +30,11 @@ module Arel
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 @@ module Arel
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