Skip to content

Commit 14d80d0

Browse files
corona10miss-islington
authored andcommitted
bpo-39425: Fix list.count performance regression (GH-18119)
https://bugs.python.org/issue39425 Automerge-Triggered-By: @pablogsal
1 parent 5bbac8c commit 14d80d0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Objects/listobject.c

+4
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,10 @@ list_count(PyListObject *self, PyObject *value)
25842584

25852585
for (i = 0; i < Py_SIZE(self); i++) {
25862586
PyObject *obj = self->ob_item[i];
2587+
if (obj == value) {
2588+
count++;
2589+
continue;
2590+
}
25872591
Py_INCREF(obj);
25882592
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
25892593
Py_DECREF(obj);

0 commit comments

Comments
 (0)