]> granicus.if.org Git - python/commitdiff
bpo-31586: Use _count_element fast path for real dicts.
authorOren Milman <orenmn@gmail.com>
Wed, 27 Sep 2017 03:18:21 +0000 (06:18 +0300)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Wed, 27 Sep 2017 03:18:21 +0000 (20:18 -0700)
Modules/_collectionsmodule.c

index e78399ddefa43c0ee7a7eef987520cd2fbdeb33a..b6cceee27f5627ca7bf33d040b580c9964014195 100644 (file)
@@ -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