diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2017-06-23 06:22:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-23 06:22:50 (GMT) |
commit | 073ae487b3ff9001c69d530c7555ddaa530dee16 (patch) | |
tree | ef9cf088872c339af996a8921122c5cc8aa61463 /Objects/dictobject.c | |
parent | 279a96206f3118a482d10826a1e32b272db4505d (diff) | |
download | cpython-073ae487b3ff9001c69d530c7555ddaa530dee16.zip cpython-073ae487b3ff9001c69d530c7555ddaa530dee16.tar.gz cpython-073ae487b3ff9001c69d530c7555ddaa530dee16.tar.bz2 |
bpo-29304: simplify lookdict_index() function. (GH-2273)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 808f548..8712d38 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -631,29 +631,20 @@ PyDict_New(void) static Py_ssize_t lookdict_index(PyDictKeysObject *k, Py_hash_t hash, Py_ssize_t index) { - size_t i; size_t mask = DK_MASK(k); - Py_ssize_t ix; + size_t perturb = (size_t)hash; + size_t i = (size_t)hash & mask; - i = (size_t)hash & mask; - ix = dk_get_index(k, i); - if (ix == index) { - return i; - } - if (ix == DKIX_EMPTY) { - return DKIX_EMPTY; - } - - for (size_t perturb = hash;;) { - perturb >>= PERTURB_SHIFT; - i = mask & ((i << 2) + i + perturb + 1); - ix = dk_get_index(k, i); + for (;;) { + Py_ssize_t ix = dk_get_index(k, i); if (ix == index) { return i; } if (ix == DKIX_EMPTY) { return DKIX_EMPTY; } + perturb >>= PERTURB_SHIFT; + i = mask & (i*5 + perturb + 1); } assert(0); /* NOT REACHED */ return DKIX_ERROR; |