From 93d448198b2a883639ed2c2e30f1f0fd7f002a90 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 21 Mar 2004 17:01:44 +0000 Subject: Add identity shortcut to PyObject_RichCompareBool. --- Objects/object.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Objects/object.c b/Objects/object.c index b913a06..bda27e0 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -871,9 +871,19 @@ Done: int PyObject_RichCompareBool(PyObject *v, PyObject *w, int op) { - PyObject *res = PyObject_RichCompare(v, w, op); + PyObject *res; int ok; + /* Quick result when objects are the same. + Guarantees that identity implies equality. */ + if (v == w) { + if (op == Py_EQ) + return 1; + else if (op == Py_NE) + return 0; + } + + res = PyObject_RichCompare(v, w, op); if (res == NULL) return -1; if (PyBool_Check(res)) -- cgit v0.12