Skip to content

Commit 073ae48

Browse files
authored
bpo-29304: simplify lookdict_index() function. (GH-2273)
1 parent 279a962 commit 073ae48

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

Objects/dictobject.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -631,29 +631,20 @@ PyDict_New(void)
631631
static Py_ssize_t
632632
lookdict_index(PyDictKeysObject *k, Py_hash_t hash, Py_ssize_t index)
633633
{
634-
size_t i;
635634
size_t mask = DK_MASK(k);
636-
Py_ssize_t ix;
635+
size_t perturb = (size_t)hash;
636+
size_t i = (size_t)hash & mask;
637637

638-
i = (size_t)hash & mask;
639-
ix = dk_get_index(k, i);
640-
if (ix == index) {
641-
return i;
642-
}
643-
if (ix == DKIX_EMPTY) {
644-
return DKIX_EMPTY;
645-
}
646-
647-
for (size_t perturb = hash;;) {
648-
perturb >>= PERTURB_SHIFT;
649-
i = mask & ((i << 2) + i + perturb + 1);
650-
ix = dk_get_index(k, i);
638+
for (;;) {
639+
Py_ssize_t ix = dk_get_index(k, i);
651640
if (ix == index) {
652641
return i;
653642
}
654643
if (ix == DKIX_EMPTY) {
655644
return DKIX_EMPTY;
656645
}
646+
perturb >>= PERTURB_SHIFT;
647+
i = mask & (i*5 + perturb + 1);
657648
}
658649
assert(0); /* NOT REACHED */
659650
return DKIX_ERROR;

0 commit comments

Comments
 (0)