Skip to content

Commit 3a33245

Browse files
committed
Do not report polymorphism for simple cases in IntNode
1 parent 3160191 commit 3a33245

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,6 @@ public PFrozenSet frozensetIterable(VirtualFrame frame, Object cls, Object itera
11171117
// int(x, base=10)
11181118
@Builtin(name = INT, minNumOfPositionalArgs = 1, parameterNames = {"cls", "x", "base"}, numOfPositionalOnlyArgs = 2, constructsClass = PythonBuiltinClassType.PInt)
11191119
@GenerateNodeFactory
1120-
@ReportPolymorphism
11211120
public abstract static class IntNode extends PythonTernaryBuiltinNode {
11221121

11231122
private final ConditionProfile invalidBase = ConditionProfile.createBinaryProfile();
@@ -1390,17 +1389,20 @@ Object createInt(Object cls, double arg, @SuppressWarnings("unused") PNone base,
13901389
// String
13911390

13921391
@Specialization(guards = "isNoValue(base)")
1392+
@Megamorphic
13931393
Object createInt(VirtualFrame frame, Object cls, String arg, @SuppressWarnings("unused") PNone base) {
13941394
return stringToInt(frame, cls, arg, 10, arg);
13951395
}
13961396

13971397
@Specialization
1398+
@Megamorphic
13981399
Object parsePIntError(VirtualFrame frame, Object cls, String number, int base) {
13991400
checkBase(base);
14001401
return stringToInt(frame, cls, number, base, number);
14011402
}
14021403

14031404
@Specialization(guards = "!isNoValue(base)", limit = "getCallSiteInlineCacheMaxDepth()")
1405+
@Megamorphic
14041406
Object createIntError(VirtualFrame frame, Object cls, String number, Object base,
14051407
@CachedLibrary("base") PythonObjectLibrary lib) {
14061408
int intBase = lib.asSizeWithState(base, null, PArguments.getThreadState(frame));
@@ -1410,18 +1412,21 @@ Object createIntError(VirtualFrame frame, Object cls, String number, Object base
14101412

14111413
// PIBytesLike
14121414
@Specialization
1415+
@Megamorphic
14131416
Object parseBytesError(VirtualFrame frame, Object cls, PBytesLike arg, int base) {
14141417
checkBase(base);
14151418
return stringToInt(frame, cls, toString(arg), base, arg);
14161419
}
14171420

14181421
@Specialization(guards = "isNoValue(base)")
1422+
@Megamorphic
14191423
Object parseBytesError(VirtualFrame frame, Object cls, PBytesLike arg, @SuppressWarnings("unused") PNone base) {
14201424
return parseBytesError(frame, cls, arg, 10);
14211425
}
14221426

14231427
// PString
14241428
@Specialization(guards = "isNoValue(base)", limit = "1")
1429+
@Megamorphic
14251430
Object parsePInt(VirtualFrame frame, Object cls, PString arg, @SuppressWarnings("unused") PNone base,
14261431
@CachedLibrary("arg") PythonObjectLibrary lib,
14271432
@CachedLibrary(limit = "1") PythonObjectLibrary methodLib) {
@@ -1433,6 +1438,7 @@ Object parsePInt(VirtualFrame frame, Object cls, PString arg, @SuppressWarnings(
14331438
}
14341439

14351440
@Specialization(limit = "1")
1441+
@Megamorphic
14361442
Object parsePInt(VirtualFrame frame, Object cls, PString arg, int base,
14371443
@CachedLibrary("arg") PythonObjectLibrary lib,
14381444
@CachedLibrary(limit = "1") PythonObjectLibrary methodLib) {
@@ -1471,6 +1477,7 @@ Object fail(Object cls, Object arg, Object base) {
14711477
}
14721478

14731479
@Specialization(guards = {"isNoValue(base)", "!isNoValue(obj)", "!isHandledType(obj)"}, limit = "5")
1480+
@Megamorphic
14741481
Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") PNone base,
14751482
@CachedLibrary(value = "obj") PythonObjectLibrary objectLib,
14761483
@CachedLibrary(limit = "1") PythonObjectLibrary methodLib) {
@@ -1492,7 +1499,7 @@ Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWar
14921499
if (objectLib.isBuffer(obj)) {
14931500
try {
14941501
byte[] bytes = objectLib.getBufferBytes(obj);
1495-
return stringToInt(frame, cls, toString(bytes), 10, obj);
1502+
return stringToInt(frame, cls, PythonUtils.newString(bytes), 10, obj);
14961503
} catch (UnsupportedMessageException e) {
14971504
CompilerDirectives.transferToInterpreterAndInvalidate();
14981505
throw new IllegalStateException("Object claims to be a buffer but does not support getBufferBytes()");
@@ -1591,14 +1598,8 @@ private String toString(PBytesLike pByteArray) {
15911598
CompilerDirectives.transferToInterpreterAndInvalidate();
15921599
toByteArrayNode = insert(BytesNodes.ToBytesNode.create());
15931600
}
1594-
return toString(toByteArrayNode.execute(pByteArray));
1595-
}
1596-
1597-
@TruffleBoundary
1598-
private static String toString(byte[] barr) {
1599-
return new String(barr);
1601+
return PythonUtils.newString(toByteArrayNode.execute(pByteArray));
16001602
}
1601-
16021603
}
16031604

16041605
// bool([x])

0 commit comments

Comments
 (0)