bpo-39425: Fix list.count performance regression (GH-18119) (GH-18120)
https://bugs.python.org/issue39425
Automerge-Triggered-By: @pablogsal
(cherry picked from commit 14d80d0b605d8b148e14458e4c1853a940071462)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
diff --git a/Objects/listobject.c b/Objects/listobject.c
index d506c08..73afc44 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2586,6 +2586,10 @@
for (i = 0; i < Py_SIZE(self); i++) {
PyObject *obj = self->ob_item[i];
+ if (obj == value) {
+ count++;
+ continue;
+ }
Py_INCREF(obj);
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
Py_DECREF(obj);