From 677d77d43d0a09ab2ffca1cd45f5b1b090475ec4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Aug 2010 14:33:39 -0700 Subject: PERF: this hash only ever has one value, also avoid inject --- lib/arel/algebra/relations/relation.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index e2f9f12866..d51e24d088 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -206,10 +206,12 @@ module Arel private def matching_attributes(attribute) - (@matching_attributes ||= attributes.inject({}) do |hash, a| - (hash[a.is_a?(Value) ? a.value : a.root] ||= []) << a - hash - end)[attribute.root] || [] + unless @matching_attributes + @matching_attributes = Hash[attributes.map do |a| + [a.root, a] + end] + end + [@matching_attributes[attribute.root]] || [] end def has_attribute?(attribute) -- cgit v1.2.3