Skip to content

Commit 7278959

Browse files
authored
bpo-43198: Revert 3dd2157 that removed freeslot tracking. (#25010)
1 parent 8efad61 commit 7278959

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Objects/setobject.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static int
103103
set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
104104
{
105105
setentry *table;
106+
setentry *freeslot;
106107
setentry *entry;
107108
size_t perturb;
108109
size_t mask;
@@ -118,14 +119,15 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
118119

119120
mask = so->mask;
120121
i = (size_t)hash & mask;
122+
freeslot = NULL;
121123
perturb = hash;
122124

123125
while (1) {
124126
entry = &so->table[i];
125127
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
126128
do {
127129
if (entry->hash == 0 && entry->key == NULL)
128-
goto found_unused;
130+
goto found_unused_or_dummy;
129131
if (entry->hash == hash) {
130132
PyObject *startkey = entry->key;
131133
assert(startkey != dummy);
@@ -147,12 +149,24 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
147149
goto restart;
148150
mask = so->mask;
149151
}
152+
else if (entry->hash == -1) {
153+
assert (entry->key == dummy);
154+
freeslot = entry;
155+
}
150156
entry++;
151157
} while (probes--);
152158
perturb >>= PERTURB_SHIFT;
153159
i = (i * 5 + 1 + perturb) & mask;
154160
}
155161

162+
found_unused_or_dummy:
163+
if (freeslot == NULL)
164+
goto found_unused;
165+
so->used++;
166+
freeslot->key = key;
167+
freeslot->hash = hash;
168+
return 0;
169+
156170
found_unused:
157171
so->fill++;
158172
so->used++;

0 commit comments

Comments
 (0)