Skip to content

Commit 064180b

Browse files
vstinnereendebakpt
andauthored
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 <pieter.eendebak@gmail.com>
1 parent 7e3290d commit 064180b

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎Objects/setobject.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,19 +1348,20 @@ static PyObject *
13481348
make_new_set_untracked(PyTypeObject *type, PyObject *iterable)
13491349
{
13501350
assert(PyType_Check(type));
1351-
PySetObject *so;
13521351

1353-
so = (PySetObject *)_PyType_AllocNoTrack(type, 0);
1354-
if (so == NULL)
1352+
// fields are zero-initialized by _PyType_AllocNoTrack
1353+
PySetObject *so = (PySetObject *)_PyType_AllocNoTrack(type, 0);
1354+
if (so == NULL) {
13551355
return NULL;
1356+
}
13561357

1357-
so->fill = 0;
1358-
so->used = 0;
1358+
assert(so->fill == 0);
1359+
assert(so->used == 0);
13591360
so->mask = PySet_MINSIZE - 1;
13601361
so->table = so->smalltable;
13611362
so->hash = -1;
1362-
so->finger = 0;
1363-
so->weakreflist = NULL;
1363+
assert(so->finger == 0);
1364+
assert(so->weakreflist == NULL);
13641365

13651366
if (iterable != NULL) {
13661367
if (set_update_local(so, iterable)) {

0 commit comments

Comments
 (0)