From 58c7733bf7c5c4d3559cd9bf8f99153cb1e36b49 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 Jul 2010 14:46:21 -0700 Subject: [PATCH] speed up hash calculation and hash method --- lib/arel/algebra/attributes/attribute.rb | 13 ++++++------- 1 file 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 @@ 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 @@ def christener 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 @@ def eval(row) 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 -- GitLab