mirror of https://github.com/python/cpython
Optimize common case for dict.fromkeys().
This commit is contained in:
parent
d3d0baf0a1
commit
34448790db
|
@ -1191,7 +1191,7 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
long hash;
|
long hash;
|
||||||
|
|
||||||
if (dictresize(mp, ((PyDictObject *)seq)->ma_used))
|
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
|
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
|
||||||
|
@ -1227,19 +1227,24 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
if (PyDict_CheckExact(d)) {
|
||||||
key = PyIter_Next(it);
|
while ((key = PyIter_Next(it)) != NULL) {
|
||||||
if (key == NULL) {
|
status = PyDict_SetItem(d, key, value);
|
||||||
if (PyErr_Occurred())
|
Py_DECREF(key);
|
||||||
|
if (status < 0)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
while ((key = PyIter_Next(it)) != NULL) {
|
||||||
status = PyObject_SetItem(d, key, value);
|
status = PyObject_SetItem(d, key, value);
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
goto Fail;
|
||||||
Py_DECREF(it);
|
Py_DECREF(it);
|
||||||
return d;
|
return d;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue