Skip to content

Commit ef0022e

Browse files
committed
Change Marshal::State#construct_array to use #__allocate__ instead of #set_class
1 parent 9ebdfd6 commit ef0022e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/ruby/core/marshal.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,21 +659,24 @@ def construct_old_module
659659
obj
660660
end
661661

662+
ARRAY_ALLOCATE = Array.method(:__allocate__).unbind
662663
ARRAY_APPEND = Array.instance_method(:<<)
663664

664665
def construct_array
665-
obj = []
666-
store_unique_object obj
667-
668666
if @user_class
669667
cls = get_user_class()
670668
if cls < Array
671-
Truffle::Internal::Unsafe.set_class obj, cls
669+
obj = ARRAY_ALLOCATE.bind(cls).call
672670
else
673671
# This is what MRI does, it's weird.
674-
return cls.allocate
672+
obj = cls.allocate
673+
store_unique_object obj
674+
return obj
675675
end
676+
else
677+
obj = []
676678
end
679+
store_unique_object obj
677680

678681
construct_integer.times do |_i|
679682
ARRAY_APPEND.bind(obj).call(construct)

0 commit comments

Comments
 (0)