[Python-checkins] cpython: Clean-up, simplify, and slightly speed-up bounds logic in set_pop().

raymond.hettinger python-checkins at python.org
Mon Jan 19 01:08:12 CET 2015


https://hg.python.org/cpython/rev/e110b6263951
changeset: 94216:e110b6263951
user: Raymond Hettinger <python at rcn.com>
date: Sun Jan 18 16:06:18 2015 -0800
summary:
 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.
files:
 Objects/setobject.c | 13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -658,7 +658,8 @@
 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 @@
 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;
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /