summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2020-05-03 11:51:05 (GMT)
committerGitHub <noreply@github.com>2020-05-03 11:51:05 (GMT)
commit3dd2157febae5087ca3333d24f69b6de9cbd13cd (patch)
tree561c89de1b233914a0895503e56963e0a54fd2fd /Objects
parent21893fbb74e8fde2931fbed9b511e2a41362b1ab (diff)
downloadcpython-3dd2157febae5087ca3333d24f69b6de9cbd13cd.zip
cpython-3dd2157febae5087ca3333d24f69b6de9cbd13cd.tar.gz
cpython-3dd2157febae5087ca3333d24f69b6de9cbd13cd.tar.bz2
Simplify set entry insertion logic. (GH-19881)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c18
1 files changed, 2 insertions, 16 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index bbe013b..df4a0e1 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -137,7 +137,6 @@ 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;
@@ -158,7 +157,6 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
if (entry->key == NULL)
goto found_unused;
- freeslot = NULL;
perturb = hash;
while (1) {
@@ -187,14 +185,12 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
goto restart;
mask = so->mask; /* help avoid a register spill */
}
- else if (entry->hash == -1)
- freeslot = entry;
if (i + LINEAR_PROBES <= mask) {
for (j = 0 ; j < LINEAR_PROBES ; j++) {
entry++;
if (entry->hash == 0 && entry->key == NULL)
- goto found_unused_or_dummy;
+ goto found_unused;
if (entry->hash == hash) {
PyObject *startkey = entry->key;
assert(startkey != dummy);
@@ -216,8 +212,6 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
goto restart;
mask = so->mask;
}
- else if (entry->hash == -1)
- freeslot = entry;
}
}
@@ -226,17 +220,9 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
entry = &so->table[i];
if (entry->key == NULL)
- goto found_unused_or_dummy;
+ goto found_unused;
}
- 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++;