From: Oren Milman Date: Wed, 27 Sep 2017 03:18:21 +0000 (+0300) Subject: bpo-31586: Use _count_element fast path for real dicts. X-Git-Tag: v3.7.0a2~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31aca4bf79217e6ec4c1d056d3ad7ed4dd469c78;p=python bpo-31586: Use _count_element fast path for real dicts. --- diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index e78399ddef..b6cceee27f 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -2277,7 +2277,9 @@ _count_elements(PyObject *self, PyObject *args) dict_setitem = _PyType_LookupId(&PyDict_Type, &PyId___setitem__); if (mapping_get != NULL && mapping_get == dict_get && - mapping_setitem != NULL && mapping_setitem == dict_setitem) { + mapping_setitem != NULL && mapping_setitem == dict_setitem && + PyDict_Check(mapping)) + { while (1) { /* Fast path advantages: 1. Eliminate double hashing