Reduce number of created objects in Hash#as_json

This commit is contained in:
Alexander Pauly 2020-01-09 13:21:51 +01:00
parent 3eab31c487
commit 9256ae8a38
1 changed files with 5 additions and 1 deletions

View File

@ -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