Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify set entry insertion logic. #19881

Merged
merged 2 commits into from
May 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Speed-up inner loop by skipping dummy entries
  • Loading branch information
rhettinger committed May 3, 2020
commit cc5aaf38b021fbb503218a8742e85b42aedca4b6
18 changes: 2 additions & 16 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}

Expand All @@ -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++;
Expand Down