]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112069: Do not require lock if the set has never been exposed. (gh-118069)
authorDonghee Na <donghee.na@python.org>
Thu, 25 Apr 2024 15:13:57 +0000 (00:13 +0900)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2024 15:13:57 +0000 (00:13 +0900)
Objects/setobject.c

index 0d88f4ff922d249f7b914723c653aa762869ed4a..19975e3d4d18e25ce386e3879566f265bc850073 100644 (file)
@@ -2333,6 +2333,13 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
     if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
         return -1;
 
+    if (Py_REFCNT(self) == 1 && self->fill == 0) {
+        self->hash = -1;
+        if (iterable == NULL) {
+            return 0;
+        }
+        return set_update_local(self, iterable);
+    }
     Py_BEGIN_CRITICAL_SECTION(self);
     if (self->fill)
         set_clear_internal(self);