summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-19 19:22:50 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-19 19:22:50 (GMT)
commit056fbf422de9bd73988e81053de43c733c6b3a8b (patch)
tree763ab9b0dd1e861d809e724486d3cb9726ed77f7
parent492b46f29e8a706d5f27040d58ba6727d962a548 (diff)
downloadcpython-056fbf422de9bd73988e81053de43c733c6b3a8b.zip
cpython-056fbf422de9bd73988e81053de43c733c6b3a8b.tar.gz
cpython-056fbf422de9bd73988e81053de43c733c6b3a8b.tar.bz2
Another modest speedup in PyObject_GenericGetAttr(): inline the call
to _PyType_Lookup().
-rw-r--r--Objects/object.c28
1 files 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;