Skip to content

Commit 261da32

Browse files
committed
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)
1 parent ff8cbdd commit 261da32

File tree

1 file changed

+1
-2
lines changed
  • activesupport/lib/active_support/inflector

1 file changed

+1
-2
lines changed

activesupport/lib/active_support/inflector/methods.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def camelize(term, uppercase_first_letter = true)
8989
#
9090
# 'SSLError'.underscore.camelize # => "SslError"
9191
def underscore(camel_cased_word)
92-
word = camel_cased_word.to_s.dup
93-
word.gsub!('::', '/')
92+
word = camel_cased_word.to_s.gsub('::', '/')
9493
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
9594
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
9695
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')

0 commit comments

Comments
 (0)