From 81912d4764eb8ccb1b069de46c7f78381f4b19a6 Mon Sep 17 00:00:00 2001
From: Guido van Rossum <guido@python.org>
Date: Sat, 24 Aug 2002 05:33:28 +0000
Subject: [PATCH] Speedup for PyObject_RichCompareBool():
 PyObject_RichCompare() almost always returns a bool, so avoid calling
 PyObject_IsTrue() in that case.

---
 Objects/object.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Objects/object.c b/Objects/object.c
index 04a7c1f09b..1283294a06 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -998,7 +998,10 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
 
 	if (res == NULL)
 		return -1;
-	ok = PyObject_IsTrue(res);
+	if (PyBool_Check(res))
+		ok = (res == Py_True);
+	else
+		ok = PyObject_IsTrue(res);
 	Py_DECREF(res);
 	return ok;
 }
-- 
2.40.0