aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2013-07-10 18:45:26 +0900
committerAkira Matsuda <ronnie@dio.jp>2013-07-10 19:09:16 +0900
commit261da32a84dafbe41aee82343db84d8868162d57 (patch)
tree6408c041d39d703fa50c2fde6ebc0d924d78dec7
parentff8cbdd05b22fc7992c34eb12c7aa3da495555b8 (diff)
downloadrails-261da32a84dafbe41aee82343db84d8868162d57.tar.gz
rails-261da32a84dafbe41aee82343db84d8868162d57.tar.bz2
rails-261da32a84dafbe41aee82343db84d8868162d57.zip
Speed up AS::Inflector.underscore
Benchmark: user system total real old 6.090000 0.120000 6.210000 ( 6.202039) new 5.930000 0.110000 6.040000 ( 6.042022)
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 8e546c0176..d063fcb49c 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -89,8 +89,7 @@ module ActiveSupport
#
# 'SSLError'.underscore.camelize # => "SslError"
def underscore(camel_cased_word)
- word = camel_cased_word.to_s.dup
- word.gsub!('::', '/')
+ word = camel_cased_word.to_s.gsub('::', '/')
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')