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.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index c96c0aa..795714d 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -23,6 +23,16 @@
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 @@
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*/