[Python-checkins] bpo-31586: Use _count_element fast path for real dicts.

Raymond Hettinger webhook-mailer at python.org
Tue Sep 26 23:18:27 EDT 2017


https://github.com/python/cpython/commit/31aca4bf79217e6ec4c1d056d3ad7ed4dd469c78
commit: 31aca4bf79217e6ec4c1d056d3ad7ed4dd469c78
branch: master
author: Oren Milman <orenmn at gmail.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2017-09-26T20:18:21-07:00
summary:

bpo-31586: Use _count_element fast path for real dicts.

files:
M Modules/_collectionsmodule.c

diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index e78399ddefa..b6cceee27f5 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



More information about the Python-checkins mailing list