From 7047d83ec505fb921f3dc07246a6cfe8f71f6ea6 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 12:21:22 -0300 Subject: Perf: speed up json encoding. Signed-off-by: Santiago Pastorino --- activesupport/lib/active_support/json/encoding.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 6e9d62bd16..c8cac52027 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -232,9 +232,8 @@ class Hash # 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) -- cgit v1.2.3