diff options
author | Jean Boussier <[email protected]> | 2024-11-05 19:57:46 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-11-26 15:11:05 +0900 |
commit | ee0de3fd4e02f95f42fd3fe9cb18bcfe3e7e2bf1 () | |
tree | 4063efad59cae2b049ad2261e86bcffba78aca6e /ext/json/lib | |
parent | 519701657fad62799045f6230f79de1941cc3c76 (diff) |
[ruby/json] JSON.dump: write directly into the provided IO
Ref: https://.com/ruby/json/issues/524 Rather than to buffer everything in memory. Unfortunately Ruby doesn't provide an API to write into and IO without first allocating a string, which is a bit wasteful. https://.com/ruby/json/commit/f017af6c0a
-rw-r--r-- | ext/json/lib/json/common.rb | 17 | ||||
-rw-r--r-- | ext/json/lib/json/ext/generator/state.rb | 11 |
2 files changed, 18 insertions, 10 deletions
@@ -286,7 +286,7 @@ module JSON if State === opts opts.generate(obj) else - State.generate(obj, opts) end end @@ -801,18 +801,15 @@ module JSON opts = opts.merge(:max_nesting => limit) if limit opts = merge_dump_options(opts, **kwargs) if kwargs - result = begin - generate(obj, opts) rescue JSON::NestingError raise ArgumentError, "exceed depth limit" end - - if anIO.nil? - result - else - anIO.write result - anIO - end end # Encodes string using String.encode. @@ -47,6 +47,17 @@ module JSON alias_method :merge, :configure # call-seq: to_h # # Returns the configuration instance variables as a hash, that can be |