[issue45697] PyType_IsSubtype is doing excessive work in the common case

Dennis Sweeney report at bugs.python.org
Tue Nov 2 22:14:13 EDT 2021


Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:

Interesting. It seems like several call sites already check the equality case:

---- setobject.h: ----
#define PyFrozenSet_Check(ob) \
    (Py_IS_TYPE(ob, &PyFrozenSet_Type) || \
      PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))

---- object.h: ----
static inline int _PyObject_TypeCheck(PyObject *ob, PyTypeObject *type) {
    return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
}
#define PyObject_TypeCheck(ob, type) _PyObject_TypeCheck(_PyObject_CAST(ob), type)


Perhaps it would be better to use PyObject_TypeCheck where applicable (such as in the type_call function you mention, and in abstract.c's binary_op1()).

----------
nosy: +Dennis Sweeney

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45697>
_______________________________________


More information about the Python-bugs-list mailing list