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

Pablo Galindo webhook-mailer at python.org
Wed Jan 22 13:11:26 EST 2020


https://github.com/python/cpython/commit/fdb21609d944941f0732df72dc3d07a7a9a7efea
commit: fdb21609d944941f0732df72dc3d07a7a9a7efea
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Pablo Galindo <Pablogsal at gmail.com>
date: 2020-01-22T18:11:22Z
summary:

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

https://bugs.python.org/issue39425

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

Co-authored-by: Dong-hee Na <donghee.na92 at gmail.com>

Co-authored-by: Dong-hee Na <donghee.na92 at gmail.com>

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index d506c0817336b..73afc44c39e36 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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);



More information about the Python-checkins mailing list