From 37dcaf74b63ca3d051523c6c1e9c9dac7b53c3d0 Mon Sep 17 00:00:00 2001 From: Joe Van Dyk Date: Mon, 28 Dec 2009 11:04:33 -0800 Subject: [PATCH] Avoid unnecessary allocations in Inflector.underscore --- activesupport/lib/active_support/inflector.rb | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 3ed30bd..8f8c3ff 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -204,11 +204,13 @@ module ActiveSupport # "ActiveRecord".underscore # => "active_record" # "ActiveRecord::Errors".underscore # => active_record/errors def underscore(camel_cased_word) - camel_cased_word.to_s.gsub(/::/, '/'). - gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). - gsub(/([a-z\d])([A-Z])/,'\1_\2'). - tr("-", "_"). - downcase + word = camel_cased_word.dup.to_s + word.gsub!(/::/, '/') + word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + word.tr!("-", "_") + word.downcase! + word end # Replaces underscores with dashes in the string. -- 1.5.4.3