summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-03-20 21:27:24 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-03-20 21:27:24 (GMT)
commit0bbbfc4c0b0cf84a23d2644080d09fb8af5324d2 (patch)
treef298dd7e7f9cd0ebb5e98a5bd33cd1046bc1dba5 /Objects/dictobject.c
parentce55e21c70068315e128980848f86d1d471fc41c (diff)
downloadcpython-0bbbfc4c0b0cf84a23d2644080d09fb8af5324d2.zip
cpython-0bbbfc4c0b0cf84a23d2644080d09fb8af5324d2.tar.gz
cpython-0bbbfc4c0b0cf84a23d2644080d09fb8af5324d2.tar.bz2
Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 587dad3..06cc4a8 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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);