From 9d1cfc1358487d66897ba386a5e05a920ee5e6f8 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Tue, 11 Nov 2025 20:02:32 +0530 Subject: [PATCH] gh-132657: optimize `PySet_Contains` for `frozenset` (GH-141183) (cherry picked from commit 7211a34fe1d9704935342af8c9b46725629f2d97) Co-authored-by: Kumar Aditya --- Objects/setobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Objects/setobject.c b/Objects/setobject.c index 83004e57b66c20..81eeafb82d1886 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -2731,7 +2731,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);