162
162
import org .truffleruby .language .objects .ReadObjectFieldNode ;
163
163
import org .truffleruby .language .objects .ReadObjectFieldNodeGen ;
164
164
import org .truffleruby .language .objects .TaintNode ;
165
+ import org .truffleruby .language .objects .WriteObjectFieldNode ;
166
+ import org .truffleruby .language .objects .WriteObjectFieldNodeGen ;
165
167
import org .truffleruby .language .yield .YieldNode ;
166
168
167
169
import com .oracle .truffle .api .CompilerDirectives ;
@@ -1320,6 +1322,9 @@ public Rope getRope(DynamicObject str) {
1320
1322
@ CoreMethod (names = "initialize_copy" , required = 1 )
1321
1323
public abstract static class InitializeCopyNode extends CoreMethodArrayArgumentsNode {
1322
1324
1325
+ @ Child private ReadObjectFieldNode readAssociatedNode = ReadObjectFieldNodeGen .create (Layouts .ASSOCIATED_IDENTIFIER , null );
1326
+ @ Child private WriteObjectFieldNode writeAssociatedNode ;
1327
+
1323
1328
@ Specialization (guards = "self == from" )
1324
1329
public Object initializeCopySelfIsSameAsFrom (DynamicObject self , DynamicObject from ) {
1325
1330
return self ;
@@ -1329,17 +1334,29 @@ public Object initializeCopySelfIsSameAsFrom(DynamicObject self, DynamicObject f
1329
1334
@ Specialization (guards = { "self != from" , "isRubyString(from)" , "!isNativeRope(from)" })
1330
1335
public Object initializeCopy (DynamicObject self , DynamicObject from ) {
1331
1336
StringOperations .setRope (self , rope (from ));
1332
-
1337
+ copyAssociated ( self , from );
1333
1338
return self ;
1334
1339
}
1335
1340
1336
1341
@ Specialization (guards = { "self != from" , "isRubyString(from)" , "isNativeRope(from)" })
1337
1342
public Object initializeCopyFromNative (DynamicObject self , DynamicObject from ) {
1338
1343
StringOperations .setRope (self , ((NativeRope ) rope (from )).makeCopy (getContext ().getFinalizationService ()));
1339
-
1344
+ copyAssociated ( self , from );
1340
1345
return self ;
1341
1346
}
1342
1347
1348
+ private void copyAssociated (DynamicObject self , DynamicObject from ) {
1349
+ final Object associated = readAssociatedNode .execute (from );
1350
+ if (associated != null ) {
1351
+ if (writeAssociatedNode == null ) {
1352
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1353
+ writeAssociatedNode = insert (WriteObjectFieldNodeGen .create (Layouts .ASSOCIATED_IDENTIFIER ));
1354
+ }
1355
+
1356
+ writeAssociatedNode .write (self , associated );
1357
+ }
1358
+ }
1359
+
1343
1360
protected boolean isNativeRope (DynamicObject other ) {
1344
1361
return rope (other ) instanceof NativeRope ;
1345
1362
}
0 commit comments