diff options
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 9b99bbf..00f9bc8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1184,6 +1184,25 @@ dict_fromkeys(PyObject *cls, PyObject *args) if (d == NULL) return NULL; + if (PyDict_CheckExact(d) && PyDict_CheckExact(seq)) { + PyDictObject *mp = (PyDictObject *)d; + PyObject *oldvalue; + Py_ssize_t pos = 0; + PyObject *key; + long hash; + + if (dictresize(mp, ((PyDictObject *)seq)->ma_used)) + return NULL; + + while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) { + Py_INCREF(key); + Py_INCREF(value); + if (insertdict(mp, key, hash, value)) + return NULL; + } + return d; + } + if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) { PyDictObject *mp = (PyDictObject *)d; Py_ssize_t pos = 0; |