aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/calculations.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-08-26 14:24:52 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-26 14:24:52 -0500
commit8756dd75b257b17ddda92674d4cc0db307d2153b (patch)
tree340974bea88d7bb48c0c4accdc6135b236b59c26 /activerecord/lib/active_record/calculations.rb
parent229eedfda87a7706dbb5e3e51af8707b3adae375 (diff)
downloadrails-8756dd75b257b17ddda92674d4cc0db307d2153b.tar.gz
rails-8756dd75b257b17ddda92674d4cc0db307d2153b.tar.bz2
rails-8756dd75b257b17ddda92674d4cc0db307d2153b.zip
Performance: reduce garbage created by ActiveRecord::Calculations#column_alias_for
Diffstat (limited to 'activerecord/lib/active_record/calculations.rb')
-rw-r--r--activerecord/lib/active_record/calculations.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb
index 246f87b7a9..77cc6da251 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -260,7 +260,14 @@ module ActiveRecord
# column_alias_for("count(*)") # => "count_all"
# column_alias_for("count", "id") # => "count_id"
def column_alias_for(*keys)
- connection.table_alias_for(keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_'))
+ table_name = keys.join(' ')
+ table_name.downcase!
+ table_name.gsub!(/\*/, 'all')
+ table_name.gsub!(/\W+/, ' ')
+ table_name.strip!
+ table_name.gsub!(/ +/, '_')
+
+ connection.table_alias_for(table_name)
end
def column_for(field)