diff options
author | Thomas Heller <theller@ctypes.org> | 2006-08-01 19:14:15 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2006-08-01 19:14:15 (GMT) |
commit | d61d0733cbd6ee341cbc51cc42bc065654335e23 (patch) | |
tree | c59a5eca414462e586675483026c47c2bb608908 /Modules | |
parent | 07fec3aa5a7c9fb6b1f8bae6bf6773892a702ea0 (diff) | |
download | cpython-d61d0733cbd6ee341cbc51cc42bc065654335e23.zip cpython-d61d0733cbd6ee341cbc51cc42bc065654335e23.tar.gz cpython-d61d0733cbd6ee341cbc51cc42bc065654335e23.tar.bz2 |
Speed up PyType_stgdict and PyObject_stgdict.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/stgdict.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 1ddbf85..149a7ea 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -134,16 +134,25 @@ PyType_stgdict(PyObject *obj) type = (PyTypeObject *)obj; if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS)) return NULL; - if (!type->tp_dict || !StgDict_Check(type->tp_dict)) + if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict)) return NULL; return (StgDictObject *)type->tp_dict; } /* May return NULL, but does not set an exception! */ +/* + This function should be as fast as possible, so we don't call PyType_stgdict + above but inline the code, and avoid the PyType_Check(). +*/ StgDictObject * PyObject_stgdict(PyObject *self) { - return PyType_stgdict((PyObject *)self->ob_type); + PyTypeObject *type = self->ob_type; + if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS)) + return NULL; + if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict)) + return NULL; + return (StgDictObject *)type->tp_dict; } /* descr is the descriptor for a field marked as anonymous. Get all the |