int probes;
int cmp;
+ int frozenset = PyFrozenSet_CheckExact(so);
+
while (1) {
entry = &so->table[i];
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
&& unicode_eq(startkey, key))
return entry;
table = so->table;
- Py_INCREF(startkey);
- cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
- Py_DECREF(startkey);
- if (cmp < 0)
- return NULL;
- if (table != so->table || entry->key != startkey)
- return set_lookkey(so, key, hash);
+ if (frozenset) {
+ cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+ if (cmp < 0)
+ return NULL;
+ } else {
+ // incref startkey because it can be removed from the set by the compare
+ Py_INCREF(startkey);
+ cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+ Py_DECREF(startkey);
+ if (cmp < 0)
+ return NULL;
+ if (table != so->table || entry->key != startkey)
+ return set_lookkey(so, key, hash);
+ }
if (cmp > 0)
return entry;
mask = so->mask;
int
_PySet_Contains(PySetObject *so, PyObject *key)
{
+ assert(so);
+
int rv;
- Py_BEGIN_CRITICAL_SECTION(so);
- rv = set_contains_lock_held(so, key);
- Py_END_CRITICAL_SECTION();
+ if (PyFrozenSet_CheckExact(so)) {
+ rv = set_contains_lock_held(so, key);
+ } else {
+ Py_BEGIN_CRITICAL_SECTION(so);
+ rv = set_contains_lock_held(so, key);
+ Py_END_CRITICAL_SECTION();
+ }
return rv;
}