Skip to content

Commit eb20a7d

Browse files
authored
gh-112069: Do not require lock if the set has never been exposed. (gh-118069)
1 parent 1723c76 commit eb20a7d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Objects/setobject.c

+7
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,13 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
23332333
if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
23342334
return -1;
23352335

2336+
if (Py_REFCNT(self) == 1 && self->fill == 0) {
2337+
self->hash = -1;
2338+
if (iterable == NULL) {
2339+
return 0;
2340+
}
2341+
return set_update_local(self, iterable);
2342+
}
23362343
Py_BEGIN_CRITICAL_SECTION(self);
23372344
if (self->fill)
23382345
set_clear_internal(self);

0 commit comments

Comments
 (0)