summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-17 11:45:00 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 00:02:58 +0900
commit768668a4de144b348f7df59f680a644fe8c46928 (patch)
treeefc13c0905951fec31b32616d737f1777348ab60 /ext
parent104089ce022437ca3b8dc00dcfa5c73dc55469f3 (diff)
[flori/json] Remove unnecessary code
In `JSON#generate` and `JSON#fast_generate`: - When the given `opts` is a `JSON::State` the variable is set to `nil`. - But it will be never used as the next `if` blocks will not be executed. - `JSON::State#configure` does the conversion to `Hash`, the conversions in the `if` block are just duplication. - `JSON::State.new` does the same thing with `configure` when an argument is given. https://github.com/flori/json/commit/5d9ab87f8e
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8091
Diffstat (limited to 'ext')
-rw-r--r--ext/json/lib/json/common.rb28
1 files changed, 4 insertions, 24 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index ea46896fcc..173af04be0 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -295,19 +295,9 @@ module JSON
#
def generate(obj, opts = nil)
if State === opts
- state, opts = opts, nil
+ state = opts
else
- state = State.new
- end
- if opts
- if opts.respond_to? :to_hash
- opts = opts.to_hash
- elsif opts.respond_to? :to_h
- opts = opts.to_h
- else
- raise TypeError, "can't convert #{opts.class} into Hash"
- end
- state = state.configure(opts)
+ state = State.new(opts)
end
state.generate(obj)
end
@@ -334,19 +324,9 @@ module JSON
# JSON.fast_generate(a)
def fast_generate(obj, opts = nil)
if State === opts
- state, opts = opts, nil
+ state = opts
else
- state = JSON.create_fast_state
- end
- if opts
- if opts.respond_to? :to_hash
- opts = opts.to_hash
- elsif opts.respond_to? :to_h
- opts = opts.to_h
- else
- raise TypeError, "can't convert #{opts.class} into Hash"
- end
- state.configure(opts)
+ state = JSON.create_fast_state.configure(opts)
end
state.generate(obj)
end