Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ea9080

Browse files
committed
Improve code clarity by removing two unattractive macros.
1 parent 8f8839e commit 4ea9080

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

Objects/setobject.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ static PyObject _dummy_struct;
4545
/* Exported for the gdb plugin's benefit. */
4646
PyObject *_PySet_Dummy = dummy;
4747

48-
#define INIT_NONZERO_SET_SLOTS(so) do { \
49-
(so)->table = (so)->smalltable; \
50-
(so)->mask = PySet_MINSIZE - 1; \
51-
(so)->hash = -1; \
52-
} while(0)
53-
54-
#define EMPTY_TO_MINSIZE(so) do { \
55-
memset((so)->smalltable, 0, sizeof((so)->smalltable)); \
56-
(so)->used = (so)->fill = 0; \
57-
INIT_NONZERO_SET_SLOTS(so); \
58-
} while(0)
5948

6049
/* ======================================================================== */
6150
/* ======= Begin logic for probing the hash table ========================= */
@@ -439,6 +428,17 @@ set_discard_key(PySetObject *so, PyObject *key)
439428
return DISCARD_FOUND;
440429
}
441430

431+
static void
432+
set_empty_to_minsize(PySetObject *so)
433+
{
434+
memset(so->smalltable, 0, sizeof(so->smalltable));
435+
so->fill = 0;
436+
so->used = 0;
437+
so->mask = PySet_MINSIZE - 1;
438+
so->table = so->smalltable;
439+
so->hash = -1;
440+
}
441+
442442
static int
443443
set_clear_internal(PySetObject *so)
444444
{
@@ -466,7 +466,7 @@ set_clear_internal(PySetObject *so)
466466
*/
467467
fill = so->fill;
468468
if (table_is_malloced)
469-
EMPTY_TO_MINSIZE(so);
469+
set_empty_to_minsize(so);
470470

471471
else if (fill > 0) {
472472
/* It's a small table with something that needs to be cleared.
@@ -475,7 +475,7 @@ set_clear_internal(PySetObject *so)
475475
*/
476476
memcpy(small_copy, table, sizeof(small_copy));
477477
table = small_copy;
478-
EMPTY_TO_MINSIZE(so);
478+
set_empty_to_minsize(so);
479479
}
480480
/* else it's a small table that's already empty */
481481

@@ -1016,11 +1016,13 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
10161016
so = (PySetObject *)type->tp_alloc(type, 0);
10171017
if (so == NULL)
10181018
return NULL;
1019-
/* tp_alloc has already zeroed the structure */
1020-
assert(so->table == NULL && so->fill == 0 && so->used == 0);
1021-
INIT_NONZERO_SET_SLOTS(so);
10221019

1020+
so->fill = 0;
1021+
so->used = 0;
1022+
so->mask = PySet_MINSIZE - 1;
1023+
so->table = so->smalltable;
10231024
so->lookup = set_lookkey_unicode;
1025+
so->hash = -1;
10241026
so->weakreflist = NULL;
10251027

10261028
if (iterable != NULL) {

0 commit comments

Comments
 (0)