Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93d4481

Browse files
committed
Add identity shortcut to PyObject_RichCompareBool.
1 parent 07973da commit 93d4481

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Objects/object.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,19 @@ PyObject_RichCompare(PyObject *v, PyObject *w, int op)
871871
int
872872
PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
873873
{
874-
PyObject *res = PyObject_RichCompare(v, w, op);
874+
PyObject *res;
875875
int ok;
876876

877+
/* Quick result when objects are the same.
878+
Guarantees that identity implies equality. */
879+
if (v == w) {
880+
if (op == Py_EQ)
881+
return 1;
882+
else if (op == Py_NE)
883+
return 0;
884+
}
885+
886+
res = PyObject_RichCompare(v, w, op);
877887
if (res == NULL)
878888
return -1;
879889
if (PyBool_Check(res))

0 commit comments

Comments
 (0)