]> granicus.if.org Git - python/commitdiff
[3.6] bpo-31586: Use _count_element fast path for real dicts. (#3776)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 27 Sep 2017 03:45:57 +0000 (20:45 -0700)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Wed, 27 Sep 2017 03:45:57 +0000 (20:45 -0700)
(cherry picked from commit 31aca4bf79217e6ec4c1d056d3ad7ed4dd469c78)

Modules/_collectionsmodule.c

index e7a24f3f058ce062c2665d5d1c233a0ed888ca75..af20d6edd9185915b4ddb089eef0b1bf2aefb5c0 100644 (file)
@@ -2276,7 +2276,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