mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
Extend work on rev 52962 and 53830 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
This commit is contained in:
parent
42f4cfa9b6
commit
f94e89c578
4 changed files with 44 additions and 5 deletions
|
@ -1175,6 +1175,24 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
|||
if (d == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) {
|
||||
dictobject *mp = (dictobject *)d;
|
||||
Py_ssize_t pos = 0;
|
||||
PyObject *key;
|
||||
long hash;
|
||||
|
||||
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
||||
return NULL;
|
||||
|
||||
while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
|
||||
Py_INCREF(key);
|
||||
Py_INCREF(Py_None);
|
||||
if (insertdict(mp, key, hash, Py_None))
|
||||
return NULL;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
it = PyObject_GetIter(seq);
|
||||
if (it == NULL){
|
||||
Py_DECREF(d);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue