From 9256ae8a389fd40f9e4f152737de0fb2c6059daf Mon Sep 17 00:00:00 2001 From: Alexander Pauly Date: Thu, 9 Jan 2020 13:21:51 +0100 Subject: [PATCH] Reduce number of created objects in Hash#as_json --- activesupport/lib/active_support/core_ext/object/json.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 416059d17bc..d92af19137c 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -169,7 +169,11 @@ class Hash self end - Hash[subset.map { |k, v| [k.to_s, options ? v.as_json(options.dup) : v.as_json] }] + result = {} + subset.each do |k, v| + result[k.to_s] = options ? v.as_json(options.dup) : v.as_json + end + result end end