提交 7047d83e 编写于 作者: E Emilio Tagua 提交者: Santiago Pastorino

Perf: speed up json encoding.

Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 418190d5
......@@ -232,9 +232,8 @@ def as_json(options = nil) #:nodoc:
# use encoder as a proxy to call as_json on all values in the subset, to protect from circular references
encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options)
pairs = subset.map { |k, v| [k.to_s, encoder.as_json(v)] }
result = self.is_a?(ActiveSupport::OrderedHash) ? ActiveSupport::OrderedHash.new : Hash.new
pairs.inject(result) { |hash, pair| hash[pair.first] = pair.last; hash }
result = self.is_a?(ActiveSupport::OrderedHash) ? ActiveSupport::OrderedHash : Hash
result[subset.map { |k, v| [k.to_s, encoder.as_json(v)] }]
end
def encode_json(encoder)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册