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

Skip to content

Commit 81912d4

Browse files
committed
Speedup for PyObject_RichCompareBool(): PyObject_RichCompare() almost
always returns a bool, so avoid calling PyObject_IsTrue() in that case.
1 parent d501851 commit 81912d4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Objects/object.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,10 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
998998

999999
if (res == NULL)
10001000
return -1;
1001-
ok = PyObject_IsTrue(res);
1001+
if (PyBool_Check(res))
1002+
ok = (res == Py_True);
1003+
else
1004+
ok = PyObject_IsTrue(res);
10021005
Py_DECREF(res);
10031006
return ok;
10041007
}

0 commit comments

Comments
 (0)