mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #17308 from pabloh/small_optimizations
Faster to call `gsub` with a regexp literal than a string literal
This commit is contained in:
commit
38259d36c4
3 changed files with 3 additions and 3 deletions
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue