diff options
author | Raymond Hettinger <python@rcn.com> | 2015-12-14 02:45:01 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-12-14 02:45:01 (GMT) |
commit | 5088f6005ff5e6bb9fbc1bdfd9777b827c6aab0f (patch) | |
tree | 14baab6a650b460e4b306e2442b05e45c5a73e5c /Objects | |
parent | 9fdaff30dbe38782f5cbda2249763fd5bd38e2c4 (diff) | |
download | cpython-5088f6005ff5e6bb9fbc1bdfd9777b827c6aab0f.zip cpython-5088f6005ff5e6bb9fbc1bdfd9777b827c6aab0f.tar.gz cpython-5088f6005ff5e6bb9fbc1bdfd9777b827c6aab0f.tar.bz2 |
Hoist constant expressions (so->table and so->mask) out of the inner-loop.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/setobject.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 7fde01f..b00e85f 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -260,16 +260,13 @@ The caller is responsible for updating the key's reference count and the setobject's fill and used fields. */ static void -set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash) +set_insert_clean(setentry *table, size_t mask, PyObject *key, Py_hash_t hash) { - setentry *table = so->table; setentry *entry; size_t perturb = hash; - size_t mask = (size_t)so->mask; size_t i = (size_t)hash & mask; size_t j; - assert(so->fill == so->used); while (1) { entry = &table[i]; if (entry->key == NULL) @@ -285,8 +282,8 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash) i = (i * 5 + 1 + perturb) & mask; } found_null: - entry->key = key; entry->hash = hash; + entry->key = key; } /* ======== End logic for probing the hash table ========================== */ @@ -304,6 +301,8 @@ set_table_resize(PySetObject *so, Py_ssize_t minused) setentry *oldtable, *newtable, *entry; Py_ssize_t oldfill = so->fill; Py_ssize_t oldused = so->used; + Py_ssize_t oldmask = so->mask; + size_t newmask; int is_oldtable_malloced; setentry small_copy[PySet_MINSIZE]; @@ -363,18 +362,17 @@ set_table_resize(PySetObject *so, Py_ssize_t minused) /* Copy the data over; this is refcount-neutral for active entries; dummy entries aren't copied over, of course */ + newmask = (size_t)so->mask; if (oldfill == oldused) { - for (entry = oldtable; oldused > 0; entry++) { + for (entry = oldtable; entry <= oldtable + oldmask; entry++) { if (entry->key != NULL) { - oldused--; - set_insert_clean(so, entry->key, entry->hash); + set_insert_clean(newtable, newmask, entry->key, entry->hash); } } } else { - for (entry = oldtable; oldused > 0; entry++) { + for (entry = oldtable; entry <= oldtable + oldmask; entry++) { if (entry->key != NULL && entry->key != dummy) { - oldused--; - set_insert_clean(so, entry->key, entry->hash); + set_insert_clean(newtable, newmask, entry->key, entry->hash); } } } @@ -676,13 +674,15 @@ set_merge(PySetObject *so, PyObject *otherset) /* If our table is empty, we can use set_insert_clean() */ if (so->fill == 0) { + setentry *newtable = so->table; + size_t newmask = (size_t)so->mask; so->fill = other->used; so->used = other->used; for (i = 0; i <= other->mask; i++, other_entry++) { key = other_entry->key; if (key != NULL && key != dummy) { Py_INCREF(key); - set_insert_clean(so, key, other_entry->hash); + set_insert_clean(newtable, newmask, key, other_entry->hash); } } return 0; |