summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-01-19 00:06:18 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-01-19 00:06:18 (GMT)
commit9cd6a789c6bd96e89b21b796292138d77d94c5aa (patch)
treeef69ea8492916be706e0e976ec49f48ee7f18712 /Objects
parentb53f0fbf96ec0b1f9ad7ddad5e9480d17e48e27a (diff)
downloadcpython-9cd6a789c6bd96e89b21b796292138d77d94c5aa.zip
cpython-9cd6a789c6bd96e89b21b796292138d77d94c5aa.tar.gz
cpython-9cd6a789c6bd96e89b21b796292138d77d94c5aa.tar.bz2
Clean-up, simplify, and slightly speed-up bounds logic in set_pop().
Elsewhere in the setobject.c code we do a bitwise-and with the mask instead of using a conditional to reset to zero on wrap-around. Using that same technique here use gives cleaner, faster, and more consistent code.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 9dc88c8..91f341c 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -658,7 +658,8 @@ set_contains_key(PySetObject *so, PyObject *key)
static PyObject *
set_pop(PySetObject *so)
{
- Py_ssize_t i = 0;
+ /* Make sure the search finger is in bounds */
+ Py_ssize_t i = so->finger & so->mask;
setentry *entry;
PyObject *key;
@@ -668,17 +669,9 @@ set_pop(PySetObject *so)
return NULL;
}
- i = so->finger;
- /* This may be a legit search finger, or it may be a once legit
- * search finger that's out of bounds now (due to wrapping or
- * resizing). We simply make sure it's in bounds now.
- */
- if (i > so->mask)
- i = 0;
while ((entry = &so->table[i])->key == NULL || entry->key==dummy) {
i++;
- if (i > so->mask)
- i = 0;
+ i &= so->mask;
}
key = entry->key;
entry->key = dummy;