summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-10-31 18:05:55 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-10-31 18:05:55 (GMT)
commitd1f2cb37a2d1cc7b098abf6bc403fb5d43128051 (patch)
tree6474e4e081df0fe9f1ed4991835780f3443c9faa /Objects
parentc43112823b1f748822c43ad42566537580c02af2 (diff)
downloadcpython-d1f2cb37a2d1cc7b098abf6bc403fb5d43128051.zip
cpython-d1f2cb37a2d1cc7b098abf6bc403fb5d43128051.tar.gz
cpython-d1f2cb37a2d1cc7b098abf6bc403fb5d43128051.tar.bz2
only fast-path fromkeys() when the constructor returns a empty dict (closes #16345)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 27de10d..d3c5eac 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1335,49 +1335,50 @@ 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;
- Py_hash_t hash;
-
- if (dictresize(mp, Py_SIZE(seq))) {
- Py_DECREF(d);
- return NULL;
- }
-
- while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
- Py_INCREF(key);
- Py_INCREF(value);
- if (insertdict(mp, key, hash, value)) {
+ if (PyDict_CheckExact(d) && PyDict_Size(d) == 0) {
+ if (PyDict_CheckExact(seq)) {
+ PyDictObject *mp = (PyDictObject *)d;
+ PyObject *oldvalue;
+ Py_ssize_t pos = 0;
+ PyObject *key;
+ Py_hash_t hash;
+
+ if (dictresize(mp, Py_SIZE(seq))) {
Py_DECREF(d);
return NULL;
}
- }
- return d;
- }
- if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) {
- PyDictObject *mp = (PyDictObject *)d;
- Py_ssize_t pos = 0;
- PyObject *key;
- Py_hash_t hash;
-
- if (dictresize(mp, PySet_GET_SIZE(seq))) {
- Py_DECREF(d);
- return NULL;
+ while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
+ Py_INCREF(key);
+ Py_INCREF(value);
+ if (insertdict(mp, key, hash, value)) {
+ Py_DECREF(d);
+ return NULL;
+ }
+ }
+ return d;
}
+ if (PyAnySet_CheckExact(seq)) {
+ PyDictObject *mp = (PyDictObject *)d;
+ Py_ssize_t pos = 0;
+ PyObject *key;
+ Py_hash_t hash;
- while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
- Py_INCREF(key);
- Py_INCREF(value);
- if (insertdict(mp, key, hash, value)) {
+ if (dictresize(mp, PySet_GET_SIZE(seq))) {
Py_DECREF(d);
return NULL;
}
+
+ while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
+ Py_INCREF(key);
+ Py_INCREF(value);
+ if (insertdict(mp, key, hash, value)) {
+ Py_DECREF(d);
+ return NULL;
+ }
+ }
+ return d;
}
- return d;
}
it = PyObject_GetIter(seq);