https://github.com/python/cpython/commit/7211a34fe1d9704935342af8c9b46725629f2d97
commit: 7211a34fe1d9704935342af8c9b46725629f2d97
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-11-11T20:02:32+05:30
summary:

gh-132657: optimize `PySet_Contains` for `frozenset` (#141183)

files:
M Objects/setobject.c

diff --git a/Objects/setobject.c b/Objects/setobject.c
index 213bd821d8a1b9..2401176576eb62 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2747,7 +2747,9 @@ PySet_Contains(PyObject *anyset, PyObject *key)
         PyErr_BadInternalCall();
         return -1;
     }
-
+    if (PyFrozenSet_CheckExact(anyset)) {
+        return set_contains_key((PySetObject *)anyset, key);
+    }
     int rv;
     Py_BEGIN_CRITICAL_SECTION(anyset);
     rv = set_contains_key((PySetObject *)anyset, key);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to