summaryrefslogtreecommitdiff
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-02-19 03:04:45 +0000
committerRaymond Hettinger <python@rcn.com>2007-02-19 03:04:45 +0000
commit1bff7969832877398b129a97ad8d307c27c80fba (patch)
tree392e02958b3be31f28a71c77815bda867698aab4 /Objects/dictobject.c
parent497380f48c266a1d1addc4a20a93aef9a380ffdf (diff)
downloadcpython-git-1bff7969832877398b129a97ad8d307c27c80fba.tar.gz
Extend work on revision 52962: Eliminate redundant calls to PyObject_Hash().
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 901e33383f..1cb3ee6ad8 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -803,6 +803,34 @@ PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
return 1;
}
+/* Internal version of PyDict_Next that returns a hash value in addition to the key and value.*/
+int
+_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, long *phash)
+{
+ register Py_ssize_t i;
+ register Py_ssize_t mask;
+ register dictentry *ep;
+
+ if (!PyDict_Check(op))
+ return 0;
+ i = *ppos;
+ if (i < 0)
+ return 0;
+ ep = ((dictobject *)op)->ma_table;
+ mask = ((dictobject *)op)->ma_mask;
+ while (i <= mask && ep[i].me_value == NULL)
+ i++;
+ *ppos = i+1;
+ if (i > mask)
+ return 0;
+ *phash = (long)(ep[i].me_hash);
+ if (pkey)
+ *pkey = ep[i].me_key;
+ if (pvalue)
+ *pvalue = ep[i].me_value;
+ return 1;
+}
+
/* Methods */
static void
@@ -1987,6 +2015,17 @@ PyDict_Contains(PyObject *op, PyObject *key)
return ep == NULL ? -1 : (ep->me_value != NULL);
}
+/* Internal version of PyDict_Contains used when the hash value is already known */
+int
+_PyDict_Contains(PyObject *op, PyObject *key, long hash)
+{
+ dictobject *mp = (dictobject *)op;
+ dictentry *ep;
+
+ ep = (mp->ma_lookup)(mp, key, hash);
+ return ep == NULL ? -1 : (ep->me_value != NULL);
+}
+
/* Hack to implement "key in dict" */
static PySequenceMethods dict_as_sequence = {
0, /* sq_length */