@@ -1000,20 +1000,20 @@ public Object createInt(PythonClass cls, String arg, @SuppressWarnings("unused")
1000
1000
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1001
1001
@ TruffleBoundary
1002
1002
int parseInt (Object cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1003
- return parseInt (cls , new String ( getByteArray ( arg ) ), keywordArg );
1003
+ return parseInt (cls , toString ( arg ), keywordArg );
1004
1004
}
1005
1005
1006
1006
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1007
1007
@ TruffleBoundary
1008
1008
long parseLong (Object cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1009
- return parseLong (cls , new String ( getByteArray ( arg ) ), keywordArg );
1009
+ return parseLong (cls , toString ( arg ), keywordArg );
1010
1010
}
1011
1011
1012
1012
@ Specialization
1013
1013
Object parseBytesError (PythonClass cls , PIBytesLike arg , int base ,
1014
1014
@ Cached ("create()" ) BranchProfile errorProfile ) {
1015
1015
try {
1016
- return parsePInt (cls , new String ( getByteArray ( arg ) ), base );
1016
+ return parsePInt (cls , toString ( arg ), base );
1017
1017
} catch (NumberFormatException e ) {
1018
1018
errorProfile .enter ();
1019
1019
throw raise (ValueError , "invalid literal for int() with base %s: %s" , base , arg );
@@ -1144,12 +1144,17 @@ protected static boolean isHandledType(Object obj) {
1144
1144
return PGuards .isInteger (obj ) || obj instanceof Double || obj instanceof Boolean || PGuards .isString (obj ) || PGuards .isBytes (obj );
1145
1145
}
1146
1146
1147
- private byte [] getByteArray (PIBytesLike pByteArray ) {
1147
+ private String toString (PIBytesLike pByteArray ) {
1148
1148
if (toByteArrayNode == null ) {
1149
1149
CompilerDirectives .transferToInterpreterAndInvalidate ();
1150
1150
toByteArrayNode = insert (BytesNodes .ToBytesNode .create ());
1151
1151
}
1152
- return toByteArrayNode .execute (pByteArray );
1152
+ return toString (toByteArrayNode .execute (pByteArray ));
1153
+ }
1154
+
1155
+ @ TruffleBoundary
1156
+ private static String toString (byte [] barr ) {
1157
+ return new String (barr );
1153
1158
}
1154
1159
1155
1160
}
0 commit comments