summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-03-24 22:33:27 (GMT)
committerGitHub <noreply@github.com>2021-03-24 22:33:27 (GMT)
commit72789592a3491bab49f144bb292679b1484885d9 (patch)
tree1c3380f7e6dc8c7f6b26ac57ebfdffbed61c91e5
parent8efad61963809d239cac986e3f3bc4cb505ab8fe (diff)
downloadcpython-72789592a3491bab49f144bb292679b1484885d9.zip
cpython-72789592a3491bab49f144bb292679b1484885d9.tar.gz
cpython-72789592a3491bab49f144bb292679b1484885d9.tar.bz2
bpo-43198: Revert 3dd2157 that removed freeslot tracking. (#25010)
-rw-r--r--Objects/setobject.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index e8912ff..caff85c 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -103,6 +103,7 @@ static int
set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
{
setentry *table;
+ setentry *freeslot;
setentry *entry;
size_t perturb;
size_t mask;
@@ -118,6 +119,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
mask = so->mask;
i = (size_t)hash & mask;
+ freeslot = NULL;
perturb = hash;
while (1) {
@@ -125,7 +127,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
do {
if (entry->hash == 0 && entry->key == NULL)
- goto found_unused;
+ goto found_unused_or_dummy;
if (entry->hash == hash) {
PyObject *startkey = entry->key;
assert(startkey != dummy);
@@ -147,12 +149,24 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
goto restart;
mask = so->mask;
}
+ else if (entry->hash == -1) {
+ assert (entry->key == dummy);
+ freeslot = entry;
+ }
entry++;
} while (probes--);
perturb >>= PERTURB_SHIFT;
i = (i * 5 + 1 + perturb) & mask;
}
+ found_unused_or_dummy:
+ if (freeslot == NULL)
+ goto found_unused;
+ so->used++;
+ freeslot->key = key;
+ freeslot->hash = hash;
+ return 0;
+
found_unused:
so->fill++;
so->used++;