1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't dup Strings when jsonifying

This method would be called so many times and would create so many temporary garbage Strings
This commit is contained in:
Akira Matsuda 2018-04-27 03:57:08 +09:00
parent 7d2400ab61
commit 124c082d43

View file

@ -54,9 +54,13 @@ module ActiveSupport
class EscapedString < String #:nodoc: class EscapedString < String #:nodoc:
def to_json(*) def to_json(*)
if Encoding.escape_html_entities_in_json if Encoding.escape_html_entities_in_json
super.gsub ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS s = super
s.gsub! ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
s
else else
super.gsub ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS s = super
s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
s
end end
end end