Skip to content

Commit 14ad44b

Browse files
committed
Combine guards to prevent two bitlength() calls
1 parent bed63f5 commit 14ad44b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int narrowToInt(BigInteger x) {
6464
return PInt.intValue(x);
6565
}
6666

67-
@Specialization(guards = {"fitsIntoLong(x)", "!fitsIntoInt(x)"})
67+
@Specialization(guards = "fitsIntoLongButNotInt(x)")
6868
long narrowToLong(BigInteger x) {
6969
return PInt.longValue(x);
7070
}
@@ -80,6 +80,12 @@ static boolean fitsIntoInt(BigInteger x) {
8080
return x.bitLength() <= 31;
8181
}
8282

83+
@TruffleBoundary
84+
static boolean fitsIntoLongButNotInt(BigInteger x) {
85+
int bitLen = x.bitLength();
86+
return bitLen > 31 && bitLen <= 63;
87+
}
88+
8389
@TruffleBoundary
8490
static boolean fitsIntoLong(BigInteger x) {
8591
return x.bitLength() <= 63;

0 commit comments

Comments
 (0)