]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39425: Fix list.count performance regression (GH-18119) (GH-18120)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Jan 2020 18:11:22 +0000 (10:11 -0800)
committerPablo Galindo <Pablogsal@gmail.com>
Wed, 22 Jan 2020 18:11:22 +0000 (18:11 +0000)
https://bugs.python.org/issue39425

Automerge-Triggered-By: @pablogsal
(cherry picked from commit 14d80d0b605d8b148e14458e4c1853a940071462)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Objects/listobject.c

index d506c0817336b29c09e1d480b134af2868ce749a..73afc44c39e36ea2b6e73a74e925d8aec0d68514 100644 (file)
@@ -2586,6 +2586,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);