summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-21 17:01:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-21 17:01:44 (GMT)
commit93d448198b2a883639ed2c2e30f1f0fd7f002a90 (patch)
tree9346cb22d2aa1033cb6a66f273951260f18f05cf
parent07973dab97e64f661120d817865b23d88f50b93b (diff)
downloadcpython-93d448198b2a883639ed2c2e30f1f0fd7f002a90.zip
cpython-93d448198b2a883639ed2c2e30f1f0fd7f002a90.tar.gz
cpython-93d448198b2a883639ed2c2e30f1f0fd7f002a90.tar.bz2
Add identity shortcut to PyObject_RichCompareBool.
-rw-r--r--Objects/object.c12
1 files changed, 11 insertions, 1 deletions
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))