Skip to content

Commit 9e06d61

Browse files
miss-islingtoncorona10
authored andcommitted
bpo-39425: Fix list.count performance regression (GH-18119) (GH-18121)
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 5707246 commit 9e06d61

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
@@ -2537,6 +2537,10 @@ list_count(PyListObject *self, PyObject *value)
25372537

25382538
for (i = 0; i < Py_SIZE(self); i++) {
25392539
PyObject *obj = self->ob_item[i];
2540+
if (obj == value) {
2541+
count++;
2542+
continue;
2543+
}
25402544
Py_INCREF(obj);
25412545
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
25422546
Py_DECREF(obj);

0 commit comments

Comments
 (0)