summaryrefslogtreecommitdiff
path: root/ext/json/lib
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-20 12:17:32 +0900
committerKenta Murata <mrkn@mrkn.jp>2020-12-21 22:10:33 +0900
commit98cc15ed1e9193e17fad6b87cccf8f8b5ade7801 (patch)
treeabc25c0a1e0509478e7d86045160897477b22e84 /ext/json/lib
parentd84dd66da065cc40da69df5e042205209411c086 (diff)
[json] Stop using prototype objects
Diffstat (limited to 'ext/json/lib')
-rw-r--r--ext/json/lib/json/common.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index 111d70c3322..c34fa61eb7d 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -71,22 +71,27 @@ module JSON
end
self.state = generator::State
const_set :State, self.state
- const_set :SAFE_STATE_PROTOTYPE, State.new
- const_set :FAST_STATE_PROTOTYPE, State.new(
+ ensure
+ $VERBOSE = old
+ end
+
+ def create_fast_state
+ State.new(
:indent => '',
:space => '',
:object_nl => "",
:array_nl => "",
:max_nesting => false
)
- const_set :PRETTY_STATE_PROTOTYPE, State.new(
+ end
+
+ def create_pretty_state
+ State.new(
:indent => ' ',
:space => ' ',
:object_nl => "\n",
:array_nl => "\n"
)
- ensure
- $VERBOSE = old
end
# Returns the JSON generator module that is used by JSON. This is
@@ -276,7 +281,7 @@ module JSON
if State === opts
state, opts = opts, nil
else
- state = SAFE_STATE_PROTOTYPE.dup
+ state = State.new
end
if opts
if opts.respond_to? :to_hash
@@ -315,7 +320,7 @@ module JSON
if State === opts
state, opts = opts, nil
else
- state = FAST_STATE_PROTOTYPE.dup
+ state = JSON.create_fast_state
end
if opts
if opts.respond_to? :to_hash
@@ -370,7 +375,7 @@ module JSON
if State === opts
state, opts = opts, nil
else
- state = PRETTY_STATE_PROTOTYPE.dup
+ state = JSON.create_pretty_state
end
if opts
if opts.respond_to? :to_hash