提交 8b611b70 编写于 作者: S Sean Griffin

Merge pull request #17483 from pabloh/optimize_gsub_calls

Call gsub with a Regexp instead of a String for better performance
......@@ -102,7 +102,7 @@ def perform_write(json, options)
end
end
message = json.gsub("\n", "\ndata: ")
message = json.gsub(/\n/, "\ndata: ")
@stream.write "data: #{message}\n\n"
end
end
......
......@@ -123,7 +123,7 @@ def content_tag(name, content_or_options_with_block = nil, options = nil, escape
# cdata_section("hello]]>world")
# # => <![CDATA[hello]]]]><![CDATA[>world]]>
def cdata_section(content)
splitted = content.to_s.gsub(']]>', ']]]]><![CDATA[>')
splitted = content.to_s.gsub(/\]\]\>/, ']]]]><![CDATA[>')
"<![CDATA[#{splitted}]]>".html_safe
end
......
......@@ -2,7 +2,7 @@ module ActionView
module Template::Handlers
class Raw
def call(template)
escaped = template.source.gsub(':', '\:')
escaped = template.source.gsub(/:/, '\:')
'%q:' + escaped + ':;'
end
......
......@@ -134,7 +134,7 @@ def replace_bind_variables(statement, values) #:nodoc:
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
bound = values.dup
c = connection
statement.gsub('?') do
statement.gsub(/\?/) do
replace_bind_variable(bound.shift, c)
end
end
......
......@@ -73,7 +73,7 @@ def camelize(term, uppercase_first_letter = true)
string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
end
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
string.gsub!('/', '::')
string.gsub!(/\//, '::')
string
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册