Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ee588f

Browse files
committed
Restore quick exit (no freeslot check) for common case (found null on first probe).
1 parent 81fdd0b commit 6ee588f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Objects/setobject.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
142142

143143
entry = &table[i];
144144
if (entry->key == NULL)
145-
goto found_null;
145+
goto found_null_first;
146+
147+
freeslot = NULL;
148+
perturb = hash;
146149

147150
while (1) {
148151
if (entry->hash == hash) {
@@ -207,6 +210,13 @@ set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
207210
goto found_null;
208211
}
209212

213+
found_null_first:
214+
so->fill++;
215+
so->used++;
216+
entry->key = key;
217+
entry->hash = hash;
218+
return 0;
219+
210220
found_null:
211221
if (freeslot == NULL) {
212222
/* UNUSED */

0 commit comments

Comments
 (0)