37
37
class BasicObject
38
38
private def __marshal__ ( ms )
39
39
out = ms . serialize_extended_object self
40
- out << 'o'
40
+ Primitive . string_binary_append out , 'o'
41
41
cls = Primitive . object_class self
42
42
43
43
if Primitive . module_anonymous? ( cls )
44
44
raise ::TypeError , "can't dump anonymous class #{ cls } "
45
45
end
46
46
47
47
name = Primitive . module_name cls
48
- out << ms . serialize ( name . to_sym )
49
- out << ms . serialize_instance_variables_suffix ( self , true )
48
+ Primitive . string_binary_append out , ms . serialize ( name . to_sym )
49
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self , true )
50
50
end
51
51
end
52
52
@@ -59,15 +59,15 @@ class Class
59
59
end
60
60
61
61
name = Primitive . module_name self
62
- "c#{ ms . serialize_integer ( name . bytesize ) } #{ name . b } "
62
+ Truffle :: Type . binary_string ( "c#{ ms . serialize_integer ( name . bytesize ) } #{ name . b } " )
63
63
end
64
64
end
65
65
66
66
class Module
67
67
private def __marshal__ ( ms )
68
68
raise TypeError , "can't dump anonymous module #{ self } " if Primitive . module_anonymous? ( self )
69
69
name = Primitive . module_name self
70
- "m#{ ms . serialize_integer ( name . bytesize ) } #{ name . b } "
70
+ Truffle :: Type . binary_string ( "m#{ ms . serialize_integer ( name . bytesize ) } #{ name . b } " )
71
71
end
72
72
end
73
73
@@ -111,29 +111,29 @@ class Exception
111
111
# identical.
112
112
private def __marshal__ ( ms )
113
113
out = ms . serialize_extended_object self
114
- out << 'o'
114
+ Primitive . string_binary_append out , 'o'
115
115
cls = Primitive . object_class self
116
116
117
117
if Primitive . module_anonymous? ( cls )
118
118
raise TypeError , "can't dump anonymous class #{ cls } "
119
119
end
120
120
121
121
name = Primitive . module_name cls
122
- out << ms . serialize ( name . to_sym )
122
+ Primitive . string_binary_append out , ms . serialize ( name . to_sym )
123
123
124
124
ivars = Primitive . object_ivars ( self )
125
125
number_of_ivars = ivars . size + 2
126
126
cause = self . cause
127
- out << ms . serialize_fixnum ( cause ? number_of_ivars + 1 : number_of_ivars )
128
- out << ms . serialize ( :mesg )
129
- out << ms . serialize ( Truffle ::ExceptionOperations . compute_message ( self ) )
130
- out << ms . serialize ( :bt )
131
- out << ms . serialize ( self . backtrace )
127
+ Primitive . string_binary_append out , ms . serialize_fixnum ( cause ? number_of_ivars + 1 : number_of_ivars )
128
+ Primitive . string_binary_append out , ms . serialize ( :mesg )
129
+ Primitive . string_binary_append out , ms . serialize ( Truffle ::ExceptionOperations . compute_message ( self ) )
130
+ Primitive . string_binary_append out , ms . serialize ( :bt )
131
+ Primitive . string_binary_append out , ms . serialize ( self . backtrace )
132
132
if cause
133
- out << ms . serialize ( :cause )
134
- out << ms . serialize ( cause )
133
+ Primitive . string_binary_append out , ms . serialize ( :cause )
134
+ Primitive . string_binary_append out , ms . serialize ( cause )
135
135
end
136
- out << Truffle ::Type . binary_string ( ms . serialize_instance_variables ( self , ivars ) )
136
+ Primitive . string_binary_append out , Truffle ::Type . binary_string ( ms . serialize_instance_variables ( self , ivars ) )
137
137
138
138
out
139
139
end
@@ -325,26 +325,26 @@ class Range
325
325
# values so we generate the correct dump data.
326
326
private def __marshal__ ( ms )
327
327
out = ms . serialize_extended_object self
328
- out << 'o'
328
+ Primitive . string_binary_append out , 'o'
329
329
cls = Primitive . object_class self
330
330
name = Primitive . module_name cls
331
331
if Primitive . module_anonymous? ( cls )
332
332
raise TypeError , "can't dump anonymous class #{ cls } "
333
333
end
334
- out << ms . serialize ( name . to_sym )
334
+ Primitive . string_binary_append out , ms . serialize ( name . to_sym )
335
335
336
336
ivars = self . instance_variables
337
- out << ms . serialize_integer ( 3 + ivars . size )
338
- out << ms . serialize ( :begin )
339
- out << ms . serialize ( self . begin )
340
- out << ms . serialize ( :end )
341
- out << ms . serialize ( self . end )
342
- out << ms . serialize ( :excl )
343
- out << ms . serialize ( self . exclude_end? )
337
+ Primitive . string_binary_append out , ms . serialize_integer ( 3 + ivars . size )
338
+ Primitive . string_binary_append out , ms . serialize ( :begin )
339
+ Primitive . string_binary_append out , ms . serialize ( self . begin )
340
+ Primitive . string_binary_append out , ms . serialize ( :end )
341
+ Primitive . string_binary_append out , ms . serialize ( self . end )
342
+ Primitive . string_binary_append out , ms . serialize ( :excl )
343
+ Primitive . string_binary_append out , ms . serialize ( self . exclude_end? )
344
344
ivars . each do |ivar |
345
345
val = Primitive . object_ivar_get self , ivar
346
- out << ms . serialize ( ivar )
347
- out << ms . serialize ( val )
346
+ Primitive . string_binary_append out , ms . serialize ( ivar )
347
+ Primitive . string_binary_append out , ms . serialize ( val )
348
348
end
349
349
out
350
350
end
@@ -382,10 +382,10 @@ class Symbol
382
382
class String
383
383
private def __marshal__ ( ms )
384
384
out = ms . serialize_instance_variables_prefix ( self )
385
- out << ms . serialize_extended_object ( self )
386
- out << ms . serialize_user_class ( self , String )
387
- out << ms . serialize_string ( self )
388
- out << ms . serialize_instance_variables_suffix ( self )
385
+ Primitive . string_binary_append out , ms . serialize_extended_object ( self )
386
+ Primitive . string_binary_append out , ms . serialize_user_class ( self , String )
387
+ Primitive . string_binary_append out , ms . serialize_string ( self )
388
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self )
389
389
out
390
390
end
391
391
end
@@ -400,12 +400,12 @@ class Regexp
400
400
private def __marshal__ ( ms )
401
401
str = self . source
402
402
out = ms . serialize_instance_variables_prefix ( self )
403
- out << ms . serialize_extended_object ( self )
404
- out << ms . serialize_user_class ( self , Regexp )
405
- out << '/'
406
- out << ms . serialize_integer ( str . bytesize ) + str . b
407
- out << ( options & Regexp ::OPTION_MASK ) . chr
408
- out << ms . serialize_instance_variables_suffix ( self )
403
+ Primitive . string_binary_append out , ms . serialize_extended_object ( self )
404
+ Primitive . string_binary_append out , ms . serialize_user_class ( self , Regexp )
405
+ Primitive . string_binary_append out , '/'
406
+ Primitive . string_binary_append out , ms . serialize_integer ( str . bytesize ) + str . b
407
+ Primitive . string_binary_append out , ( options & Regexp ::OPTION_MASK ) . chr
408
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self )
409
409
410
410
out
411
411
end
@@ -414,24 +414,24 @@ class Regexp
414
414
class Struct
415
415
private def __marshal__ ( ms )
416
416
out = ms . serialize_instance_variables_prefix ( self )
417
- out << ms . serialize_extended_object ( self )
417
+ Primitive . string_binary_append out , ms . serialize_extended_object ( self )
418
418
419
- out << 'S'
419
+ Primitive . string_binary_append out , 'S'
420
420
421
421
cls = Primitive . object_class self
422
422
if Primitive . module_anonymous? ( cls )
423
423
raise TypeError , "can't dump anonymous class #{ cls } "
424
424
end
425
425
class_name = Primitive . module_name cls
426
- out << ms . serialize ( class_name . to_sym )
427
- out << ms . serialize_integer ( self . length )
426
+ Primitive . string_binary_append out , ms . serialize ( class_name . to_sym )
427
+ Primitive . string_binary_append out , ms . serialize_integer ( self . length )
428
428
429
429
self . each_pair do |name , value |
430
- out << ms . serialize ( name )
431
- out << ms . serialize ( value )
430
+ Primitive . string_binary_append out , ms . serialize ( name )
431
+ Primitive . string_binary_append out , ms . serialize ( value )
432
432
end
433
433
434
- out << ms . serialize_instance_variables_suffix ( self )
434
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self )
435
435
436
436
out
437
437
end
@@ -440,16 +440,16 @@ class Struct
440
440
class Array
441
441
private def __marshal__ ( ms )
442
442
out = ms . serialize_instance_variables_prefix ( self )
443
- out << ms . serialize_extended_object ( self )
444
- out << ms . serialize_user_class ( self , Array )
445
- out << '['
446
- out << ms . serialize_integer ( self . length )
443
+ Primitive . string_binary_append out , ms . serialize_extended_object ( self )
444
+ Primitive . string_binary_append out , ms . serialize_user_class ( self , Array )
445
+ Primitive . string_binary_append out , '['
446
+ Primitive . string_binary_append out , ms . serialize_integer ( self . length )
447
447
unless empty?
448
448
each do |element |
449
- out << ms . serialize ( element )
449
+ Primitive . string_binary_append out , ms . serialize ( element )
450
450
end
451
451
end
452
- out << ms . serialize_instance_variables_suffix ( self )
452
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self )
453
453
454
454
out
455
455
end
@@ -460,22 +460,24 @@ class Hash
460
460
raise TypeError , "can't dump hash with default proc" if default_proc
461
461
462
462
out = ms . serialize_instance_variables_prefix ( self )
463
- out << ms . serialize_extended_object ( self )
464
- out << ms . serialize_user_class ( self , Hash )
463
+ Primitive . string_binary_append out , ms . serialize_extended_object ( self )
464
+ Primitive . string_binary_append out , ms . serialize_user_class ( self , Hash )
465
465
466
466
# A boolean property of Hash - whether it has compare_by_identity behaviour - is serialized as user class marker
467
- out << ms . serialize_user_class! ( Hash ) if compare_by_identity?
467
+ if compare_by_identity?
468
+ Primitive . string_binary_append out , ms . serialize_user_class! ( Hash )
469
+ end
468
470
469
- out << ( self . default ? '}' : '{' )
470
- out << ms . serialize_integer ( length )
471
+ Primitive . string_binary_append out , ( self . default ? '}' : '{' )
472
+ Primitive . string_binary_append out , ms . serialize_integer ( length )
471
473
unless empty?
472
474
each_pair do |key , val |
473
- out << ms . serialize ( key )
474
- out << ms . serialize ( val )
475
+ Primitive . string_binary_append out , ms . serialize ( key )
476
+ Primitive . string_binary_append out , ms . serialize ( val )
475
477
end
476
478
end
477
- out << ( self . default ? ms . serialize ( self . default ) : '' )
478
- out << ms . serialize_instance_variables_suffix ( self )
479
+ Primitive . string_binary_append out , ( self . default ? ms . serialize ( self . default ) : '' )
480
+ Primitive . string_binary_append out , ms . serialize_instance_variables_suffix ( self )
479
481
480
482
out
481
483
end
@@ -1122,16 +1124,16 @@ def serialize_extended_object(obj)
1122
1124
raise TypeError , "singleton can't be dumped"
1123
1125
end
1124
1126
1125
- str = + ''
1127
+ str = '' . b
1126
1128
Primitive . vm_extended_modules obj , -> mod do
1127
1129
if Primitive . module_anonymous? ( mod )
1128
1130
raise TypeError , "can't dump anonymous class #{ mod } "
1129
1131
end
1130
1132
1131
1133
name = Primitive . module_name ( mod )
1132
- str << "e#{ serialize ( name . to_sym ) } "
1134
+ Primitive . string_binary_append str , "e#{ serialize ( name . to_sym ) } "
1133
1135
end
1134
- Truffle :: Type . binary_string ( str )
1136
+ str
1135
1137
end
1136
1138
1137
1139
def serialize_instance_variables_prefix ( obj )
@@ -1150,26 +1152,26 @@ def serialize_instance_variables_suffix(obj, force = false)
1150
1152
1151
1153
if serialize_encoding? ( obj )
1152
1154
str = serialize_integer ( count + 1 )
1153
- str << serialize_encoding ( obj )
1155
+ Primitive . string_binary_append str , serialize_encoding ( obj )
1154
1156
else
1155
1157
str = serialize_integer ( count )
1156
1158
end
1157
1159
1158
- str << serialize_instance_variables ( obj , ivars )
1160
+ Primitive . string_binary_append str , serialize_instance_variables ( obj , ivars )
1159
1161
1160
- Truffle :: Type . binary_string ( str )
1162
+ str
1161
1163
end
1162
1164
1163
1165
def serialize_instance_variables ( obj , ivars )
1164
- str = '' . b
1166
+ out = '' . b
1165
1167
1166
1168
ivars . each do |ivar |
1167
1169
val = Primitive . object_ivar_get obj , ivar
1168
- str << serialize ( ivar )
1169
- str << serialize ( val )
1170
+ Primitive . string_binary_append out , serialize ( ivar )
1171
+ Primitive . string_binary_append out , serialize ( val )
1170
1172
end
1171
1173
1172
- str
1174
+ out
1173
1175
end
1174
1176
1175
1177
def serialize_integer ( n , prefix = nil )
@@ -1274,9 +1276,11 @@ def serialize_user_defined(obj)
1274
1276
name = Primitive . module_name cls
1275
1277
1276
1278
out = serialize_instance_variables_prefix ( str )
1277
- out << Truffle ::Type . binary_string ( "u#{ serialize ( name . to_sym ) } " )
1278
- out << serialize_integer ( str . bytesize ) + str . b
1279
- out << serialize_instance_variables_suffix ( str )
1279
+ Primitive . string_binary_append out , 'u'
1280
+ Primitive . string_binary_append out , serialize ( name . to_sym )
1281
+ Primitive . string_binary_append out , serialize_integer ( str . bytesize )
1282
+ Primitive . string_binary_append out , str
1283
+ Primitive . string_binary_append out , serialize_instance_variables_suffix ( str )
1280
1284
1281
1285
out
1282
1286
end
0 commit comments