]> granicus.if.org Git - python/commitdiff
Add identity shortcut to PyObject_RichCompareBool.
authorRaymond Hettinger <python@rcn.com>
Sun, 21 Mar 2004 17:01:44 +0000 (17:01 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 21 Mar 2004 17:01:44 +0000 (17:01 +0000)
Objects/object.c

index b913a064dfecdb822bd65830454c7d490ac11a7c..bda27e0d42411e8bfb6071297417822418d6b55a 100644 (file)
@@ -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))