https://github.com/python/cpython/commit/eb20a7d12c4b2ab7931074843f8602a48b5b07bd
commit: eb20a7d12c4b2ab7931074843f8602a48b5b07bd
branch: main
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2024-04-26T00:13:57+09:00
summary:

gh-112069: Do not require lock if the set has never been exposed. (gh-118069)

files:
M Objects/setobject.c

diff --git a/Objects/setobject.c b/Objects/setobject.c
index 0d88f4ff922d24..19975e3d4d18e2 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -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);

_______________________________________________
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