mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Reduce number of created objects in Hash#to_json
Followup to 9256ae8a38
.
Since the result of `as_json` is typically encoded with `to_json`, this
patch should save the same number of allocations as the previous one.
This commit is contained in:
parent
c2d7bdc6cc
commit
144df5b104
1 changed files with 5 additions and 1 deletions
|
@ -93,7 +93,11 @@ module ActiveSupport
|
|||
when Numeric, NilClass, TrueClass, FalseClass
|
||||
value.as_json
|
||||
when Hash
|
||||
Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
|
||||
result = {}
|
||||
value.each do |k, v|
|
||||
result[jsonify(k)] = jsonify(v)
|
||||
end
|
||||
result
|
||||
when Array
|
||||
value.map { |v| jsonify(v) }
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue