summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-03-20 21:45:04 +0000
committerRaymond Hettinger <python@rcn.com>2007-03-20 21:45:04 +0000
commitf94e89c57801ffdc17c7246704c7e1c41bbc4791 (patch)
tree2efd9f3a72c85f9417cc6e511de6399fe231ad13 /Objects
parent42f4cfa9b6612206258a0735f97c863cd14e2d03 (diff)
downloadcpython-git-f94e89c57801ffdc17c7246704c7e1c41bbc4791.tar.gz
Extend work on rev 52962 and 53830 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c18
-rw-r--r--Objects/setobject.c20
2 files changed, 36 insertions, 2 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 1cb3ee6ad8..acf5ae3159 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);
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 07ba99641c..a896d937fa 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2137,7 +2137,7 @@ PySet_Add(PyObject *set, PyObject *key)
}
int
-_PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry)
+_PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key)
{
setentry *entry_ptr;
@@ -2147,7 +2147,23 @@ _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry)
}
if (set_next((PySetObject *)set, pos, &entry_ptr) == 0)
return 0;
- *entry = entry_ptr->key;
+ *key = entry_ptr->key;
+ return 1;
+}
+
+int
+_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
+{
+ setentry *entry;
+
+ if (!PyAnySet_Check(set)) {
+ PyErr_BadInternalCall();
+ return -1;
+ }
+ if (set_next((PySetObject *)set, pos, &entry) == 0)
+ return 0;
+ *key = entry->key;
+ *hash = entry->hash;
return 1;
}