mirror of https://github.com/python/cpython
Simplify set entry insertion logic. (GH-19881)
This commit is contained in:
parent
21893fbb74
commit
3dd2157feb
|
@ -137,7 +137,6 @@ static int
|
||||||
set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
{
|
{
|
||||||
setentry *table;
|
setentry *table;
|
||||||
setentry *freeslot;
|
|
||||||
setentry *entry;
|
setentry *entry;
|
||||||
size_t perturb;
|
size_t perturb;
|
||||||
size_t mask;
|
size_t mask;
|
||||||
|
@ -158,7 +157,6 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
if (entry->key == NULL)
|
if (entry->key == NULL)
|
||||||
goto found_unused;
|
goto found_unused;
|
||||||
|
|
||||||
freeslot = NULL;
|
|
||||||
perturb = hash;
|
perturb = hash;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -187,14 +185,12 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
goto restart;
|
goto restart;
|
||||||
mask = so->mask; /* help avoid a register spill */
|
mask = so->mask; /* help avoid a register spill */
|
||||||
}
|
}
|
||||||
else if (entry->hash == -1)
|
|
||||||
freeslot = entry;
|
|
||||||
|
|
||||||
if (i + LINEAR_PROBES <= mask) {
|
if (i + LINEAR_PROBES <= mask) {
|
||||||
for (j = 0 ; j < LINEAR_PROBES ; j++) {
|
for (j = 0 ; j < LINEAR_PROBES ; j++) {
|
||||||
entry++;
|
entry++;
|
||||||
if (entry->hash == 0 && entry->key == NULL)
|
if (entry->hash == 0 && entry->key == NULL)
|
||||||
goto found_unused_or_dummy;
|
goto found_unused;
|
||||||
if (entry->hash == hash) {
|
if (entry->hash == hash) {
|
||||||
PyObject *startkey = entry->key;
|
PyObject *startkey = entry->key;
|
||||||
assert(startkey != dummy);
|
assert(startkey != dummy);
|
||||||
|
@ -216,8 +212,6 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
goto restart;
|
goto restart;
|
||||||
mask = so->mask;
|
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];
|
entry = &so->table[i];
|
||||||
if (entry->key == NULL)
|
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:
|
found_unused:
|
||||||
so->fill++;
|
so->fill++;
|
||||||
so->used++;
|
so->used++;
|
||||||
|
|
Loading…
Reference in New Issue