Skip to content

Commit 692c42e

Browse files
committed
Eliminate one indirection for 'PyType_IsSubtype'.
1 parent 1d46e4b commit 692c42e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
127127
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
128128
import com.oracle.graal.python.nodes.call.PythonCallNode;
129+
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
129130
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
130131
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
131132
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -2043,4 +2044,19 @@ long doGeneric(Object n) {
20432044
return asPrimitiveNode.executeLong(n, 0, Long.BYTES);
20442045
}
20452046
}
2047+
2048+
@Builtin(name = "PyType_IsSubtype", fixedNumOfPositionalArgs = 2)
2049+
@GenerateNodeFactory
2050+
abstract static class PyType_IsSubtype extends PythonBinaryBuiltinNode {
2051+
@Child private IsSubtypeNode isSubtypeNode = IsSubtypeNode.create();
2052+
2053+
@Specialization
2054+
int doI(PythonClass a, PythonClass b) {
2055+
if (isSubtypeNode.execute(a, b)) {
2056+
return 1;
2057+
}
2058+
return 0;
2059+
}
2060+
}
2061+
20462062
}

graalpython/lib-graalpython/python_cext.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,6 @@ def PyObject_Repr(o):
808808
return repr(o)
809809

810810

811-
@may_raise(-1)
812-
def PyType_IsSubtype(a, b):
813-
return 1 if issubclass(a, b) else 0
814-
815-
816811
def PyTuple_New(size):
817812
return (None,) * size
818813

0 commit comments

Comments
 (0)