https://github.com/python/cpython/commit/064180bb0f37f66bef1204a6655e82f0b233f53d commit: 064180bb0f37f66bef1204a6655e82f0b233f53d branch: main author: Victor Stinner <[email protected]> committer: vstinner <[email protected]> date: 2026-11-04T00:35:29Z summary:
gh-160147: Optimize make_new_set_untracked() (#161191) There is no need to set PySetObject explicitly to 0/NULL, since _PyType_AllocNoTrack() already initialize memory to zeros. Co-authored-by: Pieter Eendebak <[email protected]> files: M Objects/setobject.c diff --git a/Objects/setobject.c b/Objects/setobject.c index a762edf5933e18..8c5f244d4894d8 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1348,19 +1348,20 @@ static PyObject * make_new_set_untracked(PyTypeObject *type, PyObject *iterable) { assert(PyType_Check(type)); - PySetObject *so; - so = (PySetObject *)_PyType_AllocNoTrack(type, 0); - if (so == NULL) + // fields are zero-initialized by _PyType_AllocNoTrack + PySetObject *so = (PySetObject *)_PyType_AllocNoTrack(type, 0); + if (so == NULL) { return NULL; + } - so->fill = 0; - so->used = 0; + assert(so->fill == 0); + assert(so->used == 0); so->mask = PySet_MINSIZE - 1; so->table = so->smalltable; so->hash = -1; - so->finger = 0; - so->weakreflist = NULL; + assert(so->finger == 0); + assert(so->weakreflist == NULL); if (iterable != NULL) { if (set_update_local(so, iterable)) { _______________________________________________ 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]
