Commit 9cd6a789 authored by Raymond Hettinger's avatar Raymond Hettinger

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.
parent b53f0fbf
...@@ -658,7 +658,8 @@ set_contains_key(PySetObject *so, PyObject *key) ...@@ -658,7 +658,8 @@ set_contains_key(PySetObject *so, PyObject *key)
static PyObject * static PyObject *
set_pop(PySetObject *so) 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; setentry *entry;
PyObject *key; PyObject *key;
...@@ -668,17 +669,9 @@ set_pop(PySetObject *so) ...@@ -668,17 +669,9 @@ set_pop(PySetObject *so)
return NULL; 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) { while ((entry = &so->table[i])->key == NULL || entry->key==dummy) {
i++; i++;
if (i > so->mask) i &= so->mask;
i = 0;
} }
key = entry->key; key = entry->key;
entry->key = dummy; entry->key = dummy;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment