diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2024-04-02 19:30:44 +0200 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-04-05 19:25:20 +0200 |
commit | 869220b5896e9bf5e9072254ab99779c960e3eae (patch) | |
tree | fdf5dc9f6589e40a90bb94d7552fac67789834fd /Hashtable.c | |
parent | 5846b7df4e891e3db85e2719d5d28507e0da2468 (diff) |
Use designated initializer more
Designated initializers are supported in C99 and simplify struct
initializations. All members not explicitly mentioned are default
initialized to 0, and also modern compilers can warn on of those missing
ones.
Diffstat (limited to 'Hashtable.c')
-rw-r--r-- | Hashtable.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Hashtable.c b/Hashtable.c index 2756b232..041f25eb 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -109,13 +109,15 @@ static size_t nextPrime(size_t n) { } Hashtable* Hashtable_new(size_t size, bool owner) { - Hashtable* this; - - this = xMalloc(sizeof(Hashtable)); - this->items = 0; - this->size = size ? nextPrime(size) : 13; - this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem)); - this->owner = owner; + size = size ? nextPrime(size) : 13; + + Hashtable* this = xMalloc(sizeof(Hashtable)); + *this = (Hashtable) { + .items = 0, + .size = size, + .buckets = xCalloc(size, sizeof(HashtableItem)), + .owner = owner, + }; assert(Hashtable_isConsistent(this)); return this; |