Patch #424475: Speed-up tp_compare usage, by special-casing the common

case of objects with equal types which support tp_compare. Give
type objects a tp_compare function.
Also add c<0 tests before a few PyErr_Occurred tests.
This commit is contained in:
Martin v. Löwis 2001-06-09 07:34:05 +00:00
parent 7bc50714fe
commit 0163d6d6ef
3 changed files with 62 additions and 23 deletions

View file

@ -23,6 +23,16 @@ type_getattr(PyTypeObject *t, char *name)
return NULL;
}
static int
type_compare(PyObject *v, PyObject *w)
{
/* This is called with type objects only. So we
can just compare the addresses. */
Py_uintptr_t vv = (Py_uintptr_t)v;
Py_uintptr_t ww = (Py_uintptr_t)w;
return (vv < ww) ? -1 : (vv > ww) ? 1 : 0;
}
static PyObject *
type_repr(PyTypeObject *v)
{
@ -41,12 +51,12 @@ PyTypeObject PyType_Type = {
0, /*tp_print*/
(getattrfunc)type_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
type_compare, /*tp_compare*/
(reprfunc)type_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
_Py_HashPointer, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_xxx1*/