Skip to content

Commit fdb2160

Browse files
miss-islingtoncorona10
authored andcommitted
bpo-39425: Fix list.count performance regression (GH-18119) (GH-18120)
https://bugs.python.org/issue39425 Automerge-Triggered-By: @pablogsal (cherry picked from commit 14d80d0) Co-authored-by: Dong-hee Na <[email protected]> Co-authored-by: Dong-hee Na <[email protected]>
1 parent f84f65b commit fdb2160

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Objects/listobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,10 @@ list_count(PyListObject *self, PyObject *value)
25862586

25872587
for (i = 0; i < Py_SIZE(self); i++) {
25882588
PyObject *obj = self->ob_item[i];
2589+
if (obj == value) {
2590+
count++;
2591+
continue;
2592+
}
25892593
Py_INCREF(obj);
25902594
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
25912595
Py_DECREF(obj);

0 commit comments

Comments
 (0)