]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39425: Fix list.count performance regression (GH-18119) (GH-18121)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Jan 2020 18:11:30 +0000 (10:11 -0800)
committerPablo Galindo <Pablogsal@gmail.com>
Wed, 22 Jan 2020 18:11:30 +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 d622da9e0dbf337cf7c25dffbd9c178bcc1d5f4e..856f3215e88553411e2cbee72b96aa97fde70943 100644 (file)
@@ -2537,6 +2537,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);