summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2017-06-23 06:22:50 (GMT)
committerGitHub <noreply@github.com>2017-06-23 06:22:50 (GMT)
commit073ae487b3ff9001c69d530c7555ddaa530dee16 (patch)
treeef9cf088872c339af996a8921122c5cc8aa61463 /Objects/dictobject.c
parent279a96206f3118a482d10826a1e32b272db4505d (diff)
downloadcpython-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.c21
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;