From: Raymond Hettinger Date: Sun, 21 Mar 2004 17:01:44 +0000 (+0000) Subject: Add identity shortcut to PyObject_RichCompareBool. X-Git-Tag: v2.4a1~638 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=93d448198b2a883639ed2c2e30f1f0fd7f002a90;p=thirdparty%2FPython%2Fcpython.git Add identity shortcut to PyObject_RichCompareBool. --- diff --git a/Objects/object.c b/Objects/object.c index b913a064dfec..bda27e0d4241 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))