Permalink
Browse files

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)
  • Loading branch information...
1 parent ff8cbdd commit 261da32a84dafbe41aee82343db84d8868162d57 @amatsuda amatsuda committed Jul 10, 2013
Showing with 1 addition and 2 deletions.
  1. +1 −2 activesupport/lib/active_support/inflector/methods.rb
@@ -89,8 +89,7 @@ def camelize(term, uppercase_first_letter = true)
#
# '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')

0 comments on commit 261da32

Please sign in to comment.