diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-22 12:21:22 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-22 18:08:04 -0300 |
commit | 7047d83ec505fb921f3dc07246a6cfe8f71f6ea6 (patch) | |
tree | bc1d4de995f4278af51e632ad3e829cff7e3c75c | |
parent | 418190d55c19b19bd2f1153a4367f04263557aee (diff) | |
download | rails-7047d83ec505fb921f3dc07246a6cfe8f71f6ea6.tar.gz rails-7047d83ec505fb921f3dc07246a6cfe8f71f6ea6.tar.bz2 rails-7047d83ec505fb921f3dc07246a6cfe8f71f6ea6.zip |
Perf: speed up json encoding.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 5 |
1 files changed, 2 insertions, 3 deletions
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) |