@@ -65,8 +65,10 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
6565 return entry ;
6666
6767 while (1 ) {
68- if (entry -> hash == hash && entry -> key != dummy ) { /* dummy match unlikely */
68+ if (entry -> hash == hash ) {
6969 PyObject * startkey = entry -> key ;
70+ /* startkey cannot be a dummy because the dummy hash field is -1 */
71+ assert (startkey != dummy );
7072 if (startkey == key )
7173 return entry ;
7274 if (PyUnicode_CheckExact (startkey )
@@ -83,15 +85,18 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
8385 if (cmp > 0 ) /* likely */
8486 return entry ;
8587 }
86- if (entry -> key == dummy && freeslot == NULL )
88+ if (entry -> hash == -1 && freeslot == NULL ) {
89+ assert (entry -> key == dummy );
8790 freeslot = entry ;
91+ }
8892
8993 for (j = 1 ; j <= LINEAR_PROBES ; j ++ ) {
9094 entry = & table [(i + j ) & mask ];
9195 if (entry -> key == NULL )
9296 goto found_null ;
93- if (entry -> hash == hash && entry -> key != dummy ) {
97+ if (entry -> hash == hash ) {
9498 PyObject * startkey = entry -> key ;
99+ assert (startkey != dummy );
95100 if (startkey == key )
96101 return entry ;
97102 if (PyUnicode_CheckExact (startkey )
@@ -108,8 +113,10 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
108113 if (cmp > 0 )
109114 return entry ;
110115 }
111- if (entry -> key == dummy && freeslot == NULL )
116+ if (entry -> hash == -1 && freeslot == NULL ) {
117+ assert (entry -> key == dummy );
112118 freeslot = entry ;
119+ }
113120 }
114121
115122 perturb >>= PERTURB_SHIFT ;
0 commit comments