Skip to content

Commit e6ec1fe

Browse files
committed
Use slot lookup of __int__ in CoerceToJavaLongNode
1 parent ccbefdf commit e6ec1fe

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
import com.oracle.graal.python.nodes.ErrorMessages;
5050
import com.oracle.graal.python.nodes.PNodeWithContext;
5151
import com.oracle.graal.python.nodes.PRaiseNode;
52+
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
5253
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
5354
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
5455
import com.oracle.graal.python.nodes.util.CoerceToJavaLongNodeGen.CoerceToJavaLongExactNodeGen;
5556
import com.oracle.graal.python.nodes.util.CoerceToJavaLongNodeGen.CoerceToJavaLongLossyNodeGen;
5657
import com.oracle.graal.python.util.OverflowException;
5758
import com.oracle.truffle.api.CompilerAsserts;
5859
import com.oracle.truffle.api.CompilerDirectives;
60+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5961
import com.oracle.truffle.api.dsl.Cached;
6062
import com.oracle.truffle.api.dsl.GenerateUncached;
6163
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -102,8 +104,19 @@ public long toLong(PInt x) {
102104
@Specialization(guards = "!isNumber(x)")
103105
public long toLong(Object x,
104106
@Cached PRaiseNode raise,
105-
@Cached LookupAndCallUnaryDynamicNode callIntNode) {
106-
Object result = callIntNode.executeObject(x, __INT__);
107+
@Cached("create(__INT__)") LookupAndCallUnaryNode callIntNode) {
108+
Object result = callIntNode.executeObject(null, x);
109+
return toLong(x, raise, result);
110+
}
111+
112+
@TruffleBoundary
113+
@Specialization(guards = "!isNumber(x)", replaces = "toLong")
114+
public long toLongUncached(Object x) {
115+
Object result = LookupAndCallUnaryDynamicNode.getUncached().executeObject(x, __INT__);
116+
return CoerceToJavaLongNode.this.toLong(x, PRaiseNode.getUncached(), result);
117+
}
118+
119+
private long toLong(Object x, PRaiseNode raise, Object result) {
107120
if (result == PNone.NO_VALUE) {
108121
throw raise.raise(TypeError, ErrorMessages.MUST_BE_NUMERIC, x);
109122
}

0 commit comments

Comments
 (0)