diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-05 23:15:32 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-05 23:15:32 -0700 |
commit | f22ea4dd5b20c979dbacf8fd5768659e9e4d0706 (patch) | |
tree | cf1588512938f3c892a4afc1f00871d49e63f03f /lib/arel | |
parent | 680e080bb4399312f63a699d2f103632b41be927 (diff) | |
download | rails-f22ea4dd5b20c979dbacf8fd5768659e9e4d0706.tar.gz rails-f22ea4dd5b20c979dbacf8fd5768659e9e4d0706.tar.bz2 rails-f22ea4dd5b20c979dbacf8fd5768659e9e4d0706.zip |
performance optimization
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/extensions/class.rb | 8 | ||||
-rw-r--r-- | lib/arel/extensions/object.rb | 2 | ||||
-rw-r--r-- | lib/arel/primitives/attribute.rb | 2 | ||||
-rw-r--r-- | lib/arel/primitives/value.rb | 3 | ||||
-rw-r--r-- | lib/arel/relations/join.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/relation.rb | 13 |
6 files changed, 17 insertions, 15 deletions
diff --git a/lib/arel/extensions/class.rb b/lib/arel/extensions/class.rb index 0e5b728c26..fed2ef79c7 100644 --- a/lib/arel/extensions/class.rb +++ b/lib/arel/extensions/class.rb @@ -1,12 +1,4 @@ class Class - def abstract(*methods) - methods.each do |method| - define_method method do - raise NotImplementedError - end - end - end - def hash_on(delegatee) define_method :eql? do |other| self == other diff --git a/lib/arel/extensions/object.rb b/lib/arel/extensions/object.rb index 779098f7ea..69ec6a5dce 100644 --- a/lib/arel/extensions/object.rb +++ b/lib/arel/extensions/object.rb @@ -10,7 +10,7 @@ class Object def equality_predicate_sql '=' end - + def metaclass class << self self diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb index 5895f7e9b9..30c03839e2 100644 --- a/lib/arel/primitives/attribute.rb +++ b/lib/arel/primitives/attribute.rb @@ -35,9 +35,9 @@ module Arel def ==(other) self.class == other.class and - relation == other.relation and name == other.name and @alias == other.alias and + relation == other.relation and ancestor == other.ancestor end diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb index 5142eb45ca..8ed3c4ce30 100644 --- a/lib/arel/primitives/value.rb +++ b/lib/arel/primitives/value.rb @@ -17,7 +17,8 @@ module Arel end def ==(other) - value == other.value + self.class == other.class and + value == other.value end def bind(relation) diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb index 5356e57394..c1c3150629 100644 --- a/lib/arel/relations/join.rb +++ b/lib/arel/relations/join.rb @@ -44,10 +44,10 @@ module Arel end def relation_for(attribute) - x = [externalize(relation1), externalize(relation2)].max do |r1, r2| + [externalize(relation1), externalize(relation2)].max do |r1, r2| o1, o2 = r1.relation_for(attribute), r2.relation_for(attribute) a1, a2 = o1 && o1[attribute], o2 && o2[attribute] - + attribute / a1 <=> attribute / a2 end.relation_for(attribute) end diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index cd58f0f15c..fc47a129a0 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -138,12 +138,21 @@ module Arel def attribute_for_name(name) attributes.detect { |a| a.alias_or_name.to_s == name.to_s } end - + + # TESTME - added relation_for(x)[x] because of AR def attribute_for_attribute(attribute) attributes.select { |a| a =~ attribute }.max do |a1, a2| - (attribute / a1) <=> (attribute / a2) + (attribute / relation_for(a1)[a1]) <=> (attribute / relation_for(a2)[a2]) + end + end + + def attribute_for_attribute_with_memoization(attribute) + @attribute_for_attribute ||= Hash.new do |h, a| + h[a] = attribute_for_attribute_without_memoization(a) end + @attribute_for_attribute[attribute] end + alias_method_chain :attribute_for_attribute, :memoization end include AttributeAccessable |