diff options
author | Akira Matsuda <ronnie@dio.jp> | 2018-04-27 03:57:08 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2018-04-27 03:57:08 +0900 |
commit | 124c082d43688040c43f4e4f9ea9f15fdcbec080 (patch) | |
tree | 4ede02731a2d50a4553eb1eb0ee347702b5f3d56 /activesupport | |
parent | 7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4 (diff) | |
download | rails-124c082d43688040c43f4e4f9ea9f15fdcbec080.tar.gz rails-124c082d43688040c43f4e4f9ea9f15fdcbec080.tar.bz2 rails-124c082d43688040c43f4e4f9ea9f15fdcbec080.zip |
Don't dup Strings when jsonifying
This method would be called so many times and would create so many temporary garbage Strings
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 1339c75ffe..de1b8ac8cf 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -54,9 +54,13 @@ module ActiveSupport class EscapedString < String #:nodoc: def to_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 - super.gsub ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS + s = super + s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS + s end end |