From 056fbf422de9bd73988e81053de43c733c6b3a8b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 19 Aug 2002 19:22:50 +0000 Subject: Another modest speedup in PyObject_GenericGetAttr(): inline the call to _PyType_Lookup(). --- Objects/object.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Objects/object.c b/Objects/object.c index 5120eb5..04a7c1f 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1289,7 +1289,7 @@ PyObject * PyObject_GenericGetAttr(PyObject *obj, PyObject *name) { PyTypeObject *tp = obj->ob_type; - PyObject *descr; + PyObject *descr = NULL; PyObject *res = NULL; descrgetfunc f; long dictoffset; @@ -1321,7 +1321,31 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name) goto done; } - descr = _PyType_Lookup(tp, name); + /* Inline _PyType_Lookup */ + { + int i, n; + PyObject *mro, *base, *dict; + + /* Look in tp_dict of types in MRO */ + mro = tp->tp_mro; + assert(mro != NULL); + assert(PyTuple_Check(mro)); + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + base = PyTuple_GET_ITEM(mro, i); + if (PyClass_Check(base)) + dict = ((PyClassObject *)base)->cl_dict; + else { + assert(PyType_Check(base)); + dict = ((PyTypeObject *)base)->tp_dict; + } + assert(dict && PyDict_Check(dict)); + descr = PyDict_GetItem(dict, name); + if (descr != NULL) + break; + } + } + f = NULL; if (descr != NULL) { f = descr->ob_type->tp_descr_get; -- cgit v0.12