Add identity shortcut to PyObject_RichCompareBool.

This commit is contained in:
Raymond Hettinger 2004-03-21 17:01:44 +00:00
parent 07973dab97
commit 93d448198b
1 changed files with 11 additions and 1 deletions

View 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))