Mercurial > cpython-lru_cache-weakref
diff Objects/setobject.c @ 85609:cfcc85773ecd
Improve code clarity by removing two unattractive macros.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Sat, 07 Sep 2013 21:01:29 -0700 |
| parents | 36f3f58fddce |
| children | 7d9d55fbc19c |
line wrap: on
line diff
--- a/Objects/setobject.c Sat Sep 07 20:26:50 2013 -0700 +++ b/Objects/setobject.c Sat Sep 07 21:01:29 2013 -0700 @@ -45,17 +45,6 @@ /* Exported for the gdb plugin's benefit. */ PyObject *_PySet_Dummy = dummy; -#define INIT_NONZERO_SET_SLOTS(so) do { \ - (so)->table = (so)->smalltable; \ - (so)->mask = PySet_MINSIZE - 1; \ - (so)->hash = -1; \ - } while(0) - -#define EMPTY_TO_MINSIZE(so) do { \ - memset((so)->smalltable, 0, sizeof((so)->smalltable)); \ - (so)->used = (so)->fill = 0; \ - INIT_NONZERO_SET_SLOTS(so); \ - } while(0) /* ======================================================================== */ /* ======= Begin logic for probing the hash table ========================= */ @@ -439,6 +428,17 @@ return DISCARD_FOUND; } +static void +set_empty_to_minsize(PySetObject *so) +{ + memset(so->smalltable, 0, sizeof(so->smalltable)); + so->fill = 0; + so->used = 0; + so->mask = PySet_MINSIZE - 1; + so->table = so->smalltable; + so->hash = -1; +} + static int set_clear_internal(PySetObject *so) { @@ -466,7 +466,7 @@ */ fill = so->fill; if (table_is_malloced) - EMPTY_TO_MINSIZE(so); + set_empty_to_minsize(so); else if (fill > 0) { /* It's a small table with something that needs to be cleared. @@ -475,7 +475,7 @@ */ memcpy(small_copy, table, sizeof(small_copy)); table = small_copy; - EMPTY_TO_MINSIZE(so); + set_empty_to_minsize(so); } /* else it's a small table that's already empty */ @@ -1016,11 +1016,13 @@ so = (PySetObject *)type->tp_alloc(type, 0); if (so == NULL) return NULL; - /* tp_alloc has already zeroed the structure */ - assert(so->table == NULL && so->fill == 0 && so->used == 0); - INIT_NONZERO_SET_SLOTS(so); + so->fill = 0; + so->used = 0; + so->mask = PySet_MINSIZE - 1; + so->table = so->smalltable; so->lookup = set_lookkey_unicode; + so->hash = -1; so->weakreflist = NULL; if (iterable != NULL) {
