Commit c588e904 authored by Guido van Rossum's avatar Guido van Rossum

Simple but important optimization for descr_check(): instead of the

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.
parent f2f2a2c1
...@@ -65,7 +65,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyTypeObject *type, ...@@ -65,7 +65,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyTypeObject *type,
*pres = (PyObject *)descr; *pres = (PyObject *)descr;
return 1; return 1;
} }
if (!PyObject_IsInstance(obj, (PyObject *)(descr->d_type))) { if (!PyObject_TypeCheck(obj, descr->d_type)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"descriptor '%s' for '%s' objects " "descriptor '%s' for '%s' objects "
"doesn't apply to '%s' object", "doesn't apply to '%s' object",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment