aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-08-06 14:33:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-08-06 14:33:39 -0700
commit677d77d43d0a09ab2ffca1cd45f5b1b090475ec4 (patch)
tree0b5dee3ace5f40e2b0dd68ae986e4b03b6137b99 /lib/arel
parent60f8668d41d45b21d962bdc534bbc417d22e701b (diff)
downloadrails-677d77d43d0a09ab2ffca1cd45f5b1b090475ec4.tar.gz
rails-677d77d43d0a09ab2ffca1cd45f5b1b090475ec4.tar.bz2
rails-677d77d43d0a09ab2ffca1cd45f5b1b090475ec4.zip
PERF: this hash only ever has one value, also avoid inject
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/algebra/relations/relation.rb10
1 files changed, 6 insertions, 4 deletions
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)