aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-28 14:46:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-28 14:55:00 -0700
commit58c7733bf7c5c4d3559cd9bf8f99153cb1e36b49 (patch)
treea47beb37c589a3ac42d758015234dbf339712300
parent635f11d7fb8e7382314f5484d924b755a1e91be6 (diff)
downloadrails-58c7733bf7c5c4d3559cd9bf8f99153cb1e36b49.tar.gz
rails-58c7733bf7c5c4d3559cd9bf8f99153cb1e36b49.tar.bz2
rails-58c7733bf7c5c4d3559cd9bf8f99153cb1e36b49.zip
speed up hash calculation and hash method
-rw-r--r--lib/arel/algebra/attributes/attribute.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb
index 13781f47e0..2a4b274a96 100644
--- a/lib/arel/algebra/attributes/attribute.rb
+++ b/lib/arel/algebra/attributes/attribute.rb
@@ -3,13 +3,16 @@ require 'set'
module Arel
class TypecastError < StandardError ; end
class Attribute
- attr_reader :relation, :name, :alias, :ancestor
+ attr_reader :relation, :name, :alias, :ancestor, :hash
def initialize(relation, name, options = {})
@relation = relation # this is actually a table (I think)
@name = name
@alias = options[:alias]
@ancestor = options[:ancestor]
+
+ # FIXME: I think we can remove this eventually
+ @hash = name.hash + root.relation.class.hash
end
def engine
@@ -23,10 +26,10 @@ module Arel
def == other
super ||
Attribute === other &&
- @relation == other.relation &&
@name == other.name &&
@alias == other.alias &&
- @ancestor == other.ancestor
+ @ancestor == other.ancestor &&
+ @relation == other.relation
end
alias :eql? :==
@@ -43,10 +46,6 @@ module Arel
row[self]
end
- def hash
- @hash ||= name.hash + root.relation.hash
- end
-
def as(aliaz = nil)
Attribute.new(relation, name, :alias => aliaz, :ancestor => self)
end