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

This commit is contained in:
Donghee Na 2024-04-26 00:13:57 +09:00 committed by GitHub
parent 1723c76d79
commit eb20a7d12c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View 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)) if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
return -1; 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); Py_BEGIN_CRITICAL_SECTION(self);
if (self->fill) if (self->fill)
set_clear_internal(self); set_clear_internal(self);