From 50d62bd40a30db62f435712af1011d7607140796 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 19 Apr 2024 07:52:19 +0900 Subject: [PATCH] gh-112069: Do not require lock if the set has never been exposed. --- Objects/setobject.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Objects/setobject.c b/Objects/setobject.c index 7af0ae166f9da3..04788ff197d9c0 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -2334,6 +2334,12 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds) if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable)) return -1; + if (self->fill == 0 && Py_REFCNT(self) == 1) { + if (iterable == NULL) { + return 0; + } + return set_update_local(self, iterable); + } Py_BEGIN_CRITICAL_SECTION(self); if (self->fill) set_clear_internal(self);