]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39425: Fix list.count performance regression (GH-18119)
authorDong-hee Na <donghee.na92@gmail.com>
Wed, 22 Jan 2020 17:36:54 +0000 (02:36 +0900)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Jan 2020 17:36:54 +0000 (09:36 -0800)
https://bugs.python.org/issue39425

Automerge-Triggered-By: @pablogsal
Objects/listobject.c

index bc8425cae63e12966b1044cfbcd221d1c32142e8..a4e90dbf90cf98c06bc3b2c96776fc38e13eea49 100644 (file)
@@ -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);