From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 22 Jan 2020 18:11:30 +0000 (-0800) Subject: bpo-39425: Fix list.count performance regression (GH-18119) (GH-18121) X-Git-Tag: v3.7.7rc1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e06d61af30bac4fcacb7973f826147ccc010392;p=thirdparty%2FPython%2Fcpython.git bpo-39425: Fix list.count performance regression (GH-18119) (GH-18121) https://bugs.python.org/issue39425 Automerge-Triggered-By: @pablogsal (cherry picked from commit 14d80d0b605d8b148e14458e4c1853a940071462) Co-authored-by: Dong-hee Na Co-authored-by: Dong-hee Na --- diff --git a/Objects/listobject.c b/Objects/listobject.c index d622da9e0dbf..856f3215e885 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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);