aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/sql/christener.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-26 16:35:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-26 16:35:15 -0700
commit4104de6a11c022e82a0fedd786cf39bc6c7bb62f (patch)
treeff37d737f107f83c31463420b423035fb96ab7d7 /lib/arel/engines/sql/christener.rb
parent21cf9e4a7214a97fa2c81c84cd970aac30311dda (diff)
downloadrails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.tar.gz
rails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.tar.bz2
rails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.zip
PERF: cache christener, initialize hash in initialize
Diffstat (limited to 'lib/arel/engines/sql/christener.rb')
-rw-r--r--lib/arel/engines/sql/christener.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/arel/engines/sql/christener.rb b/lib/arel/engines/sql/christener.rb
index a2a2da799a..2c96020554 100644
--- a/lib/arel/engines/sql/christener.rb
+++ b/lib/arel/engines/sql/christener.rb
@@ -1,13 +1,18 @@
module Arel
module Sql
class Christener
- def name_for(relation)
- @used_names ||= Hash.new(0)
- (@relation_names ||= Hash.new do |hash, relation|
+ def initialize
+ # FIXME: this exists because all objects hash the same. :'(
+ @used_names = Hash.new(0)
+ @relation_names = Hash.new do |hash, relation|
name = relation.table_alias ? relation.table_alias : relation.name
@used_names[name] += 1
hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '')
- end)[relation.table]
+ end
+ end
+
+ def name_for(relation)
+ @relation_names[relation.table]
end
end
end