Skip to content

Commit 870c286

Browse files
authored
bp-29304: Simplify dictobject.c (GH-2347)
replace `(i << 2) + 1` with `i*5`
1 parent 18ede06 commit 870c286

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Objects/dictobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ lookdict(PyDictObject *mp, PyObject *key,
738738

739739
for (size_t perturb = hash;;) {
740740
perturb >>= PERTURB_SHIFT;
741-
i = ((i << 2) + i + perturb + 1) & mask;
741+
i = (i*5 + perturb + 1) & mask;
742742
ix = dk_get_index(dk, i);
743743
if (ix == DKIX_EMPTY) {
744744
if (hashpos != NULL) {
@@ -834,7 +834,7 @@ lookdict_unicode(PyDictObject *mp, PyObject *key,
834834

835835
for (size_t perturb = hash;;) {
836836
perturb >>= PERTURB_SHIFT;
837-
i = mask & ((i << 2) + i + perturb + 1);
837+
i = mask & (i*5 + perturb + 1);
838838
ix = dk_get_index(mp->ma_keys, i);
839839
if (ix == DKIX_EMPTY) {
840840
if (hashpos != NULL) {
@@ -905,7 +905,7 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
905905
}
906906
for (size_t perturb = hash;;) {
907907
perturb >>= PERTURB_SHIFT;
908-
i = mask & ((i << 2) + i + perturb + 1);
908+
i = mask & (i*5 + perturb + 1);
909909
ix = dk_get_index(mp->ma_keys, i);
910910
assert (ix != DKIX_DUMMY);
911911
if (ix == DKIX_EMPTY) {
@@ -972,7 +972,7 @@ lookdict_split(PyDictObject *mp, PyObject *key,
972972
}
973973
for (size_t perturb = hash;;) {
974974
perturb >>= PERTURB_SHIFT;
975-
i = mask & ((i << 2) + i + perturb + 1);
975+
i = mask & (i*5 + perturb + 1);
976976
ix = dk_get_index(mp->ma_keys, i);
977977
if (ix == DKIX_EMPTY) {
978978
if (hashpos != NULL)
@@ -1073,7 +1073,7 @@ find_empty_slot(PyDictKeysObject *keys, PyObject *key, Py_hash_t hash)
10731073
ix = dk_get_index(keys, i);
10741074
for (size_t perturb = hash; ix != DKIX_EMPTY;) {
10751075
perturb >>= PERTURB_SHIFT;
1076-
i = (i << 2) + i + perturb + 1;
1076+
i = i*5 + perturb + 1;
10771077
ix = dk_get_index(keys, i & mask);
10781078
}
10791079
assert(DK_ENTRIES(keys)[keys->dk_nentries].me_value == NULL);
@@ -1190,7 +1190,7 @@ build_indices(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n)
11901190
size_t i = hash & mask;
11911191
for (size_t perturb = hash; dk_get_index(keys, i) != DKIX_EMPTY;) {
11921192
perturb >>= PERTURB_SHIFT;
1193-
i = mask & ((i << 2) + i + perturb + 1);
1193+
i = mask & (i*5 + perturb + 1);
11941194
}
11951195
dk_set_index(keys, i, ix);
11961196
}

0 commit comments

Comments
 (0)