@@ -444,33 +444,51 @@ public abstract static class RMulNode extends MulNode {
444
444
@ GenerateNodeFactory
445
445
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
446
446
@ TruffleBoundary
447
- private static final StringBuilder newStringBuilder () {
448
- return new StringBuilder ("b'" );
447
+ private static StringBuilder newStringBuilder () {
448
+ return new StringBuilder ();
449
449
}
450
450
451
451
@ TruffleBoundary
452
- private static final String sbFinishAndToString (StringBuilder sb ) {
453
- sb .append ("'" );
452
+ private static String sbToString (StringBuilder sb ) {
454
453
return sb .toString ();
455
454
}
456
455
456
+ @ TruffleBoundary
457
+ private static void sbAppend (StringBuilder sb , String s ) {
458
+ sb .append (s );
459
+ }
460
+
457
461
@ Specialization
458
462
public Object repr (VirtualFrame frame , PBytes self ,
459
463
@ Cached SequenceStorageNodes .LenNode lenNode ,
460
464
@ Cached SequenceStorageNodes .GetItemNode getItemNode ) {
461
465
SequenceStorage store = self .getSequenceStorage ();
462
466
int len = lenNode .execute (store );
463
467
StringBuilder sb = newStringBuilder ();
468
+ sbAppend (sb , "b'" );
464
469
for (int i = 0 ; i < len ; i ++) {
465
470
BytesUtils .byteRepr (sb , (byte ) getItemNode .executeInt (frame , store , i ));
466
471
}
467
- return sbFinishAndToString (sb );
472
+ sbAppend (sb , "'" );
473
+ return sbToString (sb );
468
474
}
469
475
470
476
@ Specialization
471
- public Object repr (PByteArray self , @ Cached ("create()" ) TypeNodes .GetNameNode getNameNode ) {
477
+ public Object repr (VirtualFrame frame , PByteArray self ,
478
+ @ Cached ("create()" ) TypeNodes .GetNameNode getNameNode ,
479
+ @ Cached SequenceStorageNodes .LenNode lenNode ,
480
+ @ Cached SequenceStorageNodes .GetItemNode getItemNode ) {
472
481
String typeName = getNameNode .execute (self .getLazyPythonClass ());
473
- return self .formatByteArray (typeName );
482
+ SequenceStorage store = self .getSequenceStorage ();
483
+ int len = lenNode .execute (store );
484
+ StringBuilder sb = newStringBuilder ();
485
+ sb .append (typeName );
486
+ sb .append ("(b'" );
487
+ for (int i = 0 ; i < len ; i ++) {
488
+ BytesUtils .byteRepr (sb , (byte ) getItemNode .executeInt (frame , store , i ));
489
+ }
490
+ sb .append ("')" );
491
+ return sbToString (sb );
474
492
}
475
493
}
476
494
0 commit comments