Simple but important optimization for descr_check(): instead of the
authorGuido van Rossum <guido@python.org>
Mon, 19 Aug 2002 16:02:33 +0000 (16:02 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 19 Aug 2002 16:02:33 +0000 (16:02 +0000)
expensive and overly general PyObject_IsInstance(), call
PyObject_TypeCheck() which is a macro that often avoids a call, and if
it does make a call, calls the much more efficient PyType_IsSubtype().
This saved 6% on a benchmark for slot lookups.

Objects/descrobject.c

index cbf9e16113847580ef8a7f97d46ee789b80cfbe2..6daffc617547cdcd02280c6c8fc492d3e849295e 100644 (file)
@@ -65,7 +65,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyTypeObject *type,
                *pres = (PyObject *)descr;
                return 1;
        }
-       if (!PyObject_IsInstance(obj, (PyObject *)(descr->d_type))) {
+       if (!PyObject_TypeCheck(obj, descr->d_type)) {
                PyErr_Format(PyExc_TypeError,
                             "descriptor '%s' for '%s' objects "
                             "doesn't apply to '%s' object",