Skip to content

Commit 6508455

Browse files
committed
Deprecate JSON.fast_generate
1 parent 346530b commit 6508455

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changes
22

3+
* Deprecate `JSON.fast_generate` (it's not any faster, so pointless).
34
* Deprecate `JSON.load_default_options`.
45
* Deprecate `JSON.unsafe_load_default_options`.
56
* Deprecate `JSON.dump_default_options`.

lib/json/common.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ def generator=(generator) # :nodoc:
7474
$VERBOSE = old
7575
end
7676

77-
def create_fast_state
78-
State.new(
79-
:indent => '',
80-
:space => '',
81-
:object_nl => "",
82-
:array_nl => "",
83-
:max_nesting => false
84-
)
85-
end
86-
8777
def create_pretty_state
8878
State.new(
8979
:indent => ' ',
@@ -368,12 +358,12 @@ def generate(obj, opts = nil)
368358
# # Raises SystemStackError (stack level too deep):
369359
# JSON.fast_generate(a)
370360
def fast_generate(obj, opts = nil)
371-
if State === opts
372-
state = opts
361+
if RUBY_VERSION >= "3.0"
362+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
373363
else
374-
state = JSON.create_fast_state.configure(opts)
364+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
375365
end
376-
state.generate(obj)
366+
generate(obj, opts)
377367
end
378368

379369
# :call-seq:

test/json/json_generator_test.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,25 +237,6 @@ def test_safe_state
237237
}.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
238238
end
239239

240-
def test_fast_state
241-
state = JSON.create_fast_state
242-
assert_equal({
243-
:allow_nan => false,
244-
:array_nl => "",
245-
:as_json => false,
246-
:ascii_only => false,
247-
:buffer_initial_length => 1024,
248-
:depth => 0,
249-
:script_safe => false,
250-
:strict => false,
251-
:indent => "",
252-
:max_nesting => 0,
253-
:object_nl => "",
254-
:space => "",
255-
:space_before => "",
256-
}.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
257-
end
258-
259240
def test_allow_nan
260241
error = assert_raise(GeneratorError) { generate([JSON::NaN]) }
261242
assert_same JSON::NaN, error.invalid_object

0 commit comments

Comments
 (0)