[Python-checkins] bpo-39425: Fix list.count performance regression (GH-18119)

Miss Islington (bot) webhook-mailer at python.org
Wed Jan 22 12:36:59 EST 2020


https://github.com/python/cpython/commit/14d80d0b605d8b148e14458e4c1853a940071462
commit: 14d80d0b605d8b148e14458e4c1853a940071462
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2020-01-22T09:36:54-08:00
summary:

bpo-39425: Fix list.count performance regression (GH-18119)



https://bugs.python.org/issue39425



Automerge-Triggered-By: @pablogsal

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index bc8425cae63e1..a4e90dbf90cf9 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);



More information about the Python-checkins mailing list