From 14d80d0b605d8b148e14458e4c1853a940071462 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 23 Jan 2020 02:36:54 +0900 Subject: [PATCH] bpo-39425: Fix list.count performance regression (GH-18119) https://bugs.python.org/issue39425 Automerge-Triggered-By: @pablogsal --- Objects/listobject.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Objects/listobject.c b/Objects/listobject.c index bc8425cae63..a4e90dbf90c 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2584,6 +2584,10 @@ list_count(PyListObject *self, PyObject *value) 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);