diff options
author | Jeremy Kemper <jeremykemper@gmail.com> | 2014-10-29 18:25:46 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremykemper@gmail.com> | 2014-10-29 18:25:46 -0700 |
commit | 38259d36c42c101482b03f4a07897df3dd857497 (patch) | |
tree | bde415444448d1d755d28c83e0e1de699720e594 | |
parent | 6dc178711de036ae9a441e83978b7ed740be2f63 (diff) | |
parent | c02a7e4f8239006ad01d1ca5d28f47cf9563920e (diff) | |
download | rails-38259d36c42c101482b03f4a07897df3dd857497.tar.gz rails-38259d36c42c101482b03f4a07897df3dd857497.tar.bz2 rails-38259d36c42c101482b03f4a07897df3dd857497.zip |
Merge pull request #17308 from pabloh/small_optimizations
Faster to call `gsub` with a regexp literal than a string literal
3 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 0e3c8517d1..637736c5df 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -90,7 +90,7 @@ module ActiveSupport # 'SSLError'.underscore.camelize # => "SslError" def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ - word = camel_cased_word.to_s.gsub('::', '/') + word = camel_cased_word.to_s.gsub(/::/, '/') word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') diff --git a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb index 9ae27a896a..fb5adb574a 100644 --- a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb @@ -13,7 +13,7 @@ module ActiveSupport end rounded_number = NumberToRoundedConverter.convert(number, options) - format.gsub('%n', rounded_number).gsub('%u', options[:unit]) + format.gsub(/%n/, rounded_number).gsub(/%u/, options[:unit]) end private diff --git a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb index eafe2844f7..1af294a03e 100644 --- a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb @@ -5,7 +5,7 @@ module ActiveSupport def convert rounded_number = NumberToRoundedConverter.convert(number, options) - options[:format].gsub('%n', rounded_number) + options[:format].gsub(/%n/, rounded_number) end end end |