Skip to content

Commit ceb7650

Browse files
committed
Only make the result of JSON.{dump,generate} mutable, not of every #to_json method
* To avoid extra unnecessary allocations. * See ruby#963
1 parent d0b47b0 commit ceb7650

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/json/truffle_ruby/generator.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def generate(obj, anIO = nil)
349349
!@ascii_only and !@script_safe and @max_nesting == 0 and (!@strict || Symbol === obj)
350350
result = generate_json(obj, ''.dup)
351351
else
352-
result = obj.to_json(self)
352+
result = +obj.to_json(self)
353353
end
354354
JSON::TruffleRuby::Generator.valid_utf8?(result) or raise GeneratorError.new(
355355
"source sequence #{result.inspect} is illegal/malformed utf-8",
@@ -517,7 +517,7 @@ def json_transform(state)
517517

518518
if empty?
519519
state.depth -= 1
520-
return +'{}'
520+
return '{}'
521521
end
522522

523523
delim = ",#{state.object_nl}"
@@ -609,7 +609,7 @@ def json_transform(state)
609609

610610
if empty?
611611
state.depth -= 1
612-
return +'[]'
612+
return '[]'
613613
end
614614

615615
result = '['.dup
@@ -736,17 +736,17 @@ def to_json(state = nil, *args)
736736

737737
module TrueClass
738738
# Returns a JSON string for true: 'true'.
739-
def to_json(*) +'true' end
739+
def to_json(*) 'true' end
740740
end
741741

742742
module FalseClass
743743
# Returns a JSON string for false: 'false'.
744-
def to_json(*) +'false' end
744+
def to_json(*) 'false' end
745745
end
746746

747747
module NilClass
748748
# Returns a JSON string for nil: 'null'.
749-
def to_json(*) +'null' end
749+
def to_json(*) 'null' end
750750
end
751751
end
752752
end

0 commit comments

Comments
 (0)