From: Zbigniew Jędrzejewski-Szmek Date: Tue, 1 Sep 2020 11:22:14 +0000 (+0200) Subject: basic/hashmap,set: move pointer symbol adjactent to the returned value X-Git-Tag: v247-rc1~319^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16922%2Fhead;p=thirdparty%2Fsystemd.git basic/hashmap,set: move pointer symbol adjactent to the returned value I think this is nicer in general, and here in particular we have a lot of code like: static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) { return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h)); } and it's visually appealing to use the same whitespace in the function signature and the cast in the body of the function. --- diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 2605cad8d92..45cc8fd7a36 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -323,12 +323,12 @@ static void n_entries_dec(HashmapBase *h) { h->n_direct_entries--; } -static void *storage_ptr(HashmapBase *h) { +static void* storage_ptr(HashmapBase *h) { return h->has_indirect ? h->indirect.storage : h->direct.storage; } -static uint8_t *hash_key(HashmapBase *h) { +static uint8_t* hash_key(HashmapBase *h) { return h->has_indirect ? h->indirect.hash_key : shared_hash_key; } @@ -371,16 +371,16 @@ static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) { memcpy(hash_key, current, sizeof(current)); } -static struct hashmap_base_entry *bucket_at(HashmapBase *h, unsigned idx) { +static struct hashmap_base_entry* bucket_at(HashmapBase *h, unsigned idx) { return (struct hashmap_base_entry*) ((uint8_t*) storage_ptr(h) + idx * hashmap_type_info[h->type].entry_size); } -static struct plain_hashmap_entry *plain_bucket_at(Hashmap *h, unsigned idx) { +static struct plain_hashmap_entry* plain_bucket_at(Hashmap *h, unsigned idx) { return (struct plain_hashmap_entry*) bucket_at(HASHMAP_BASE(h), idx); } -static struct ordered_hashmap_entry *ordered_bucket_at(OrderedHashmap *h, unsigned idx) { +static struct ordered_hashmap_entry* ordered_bucket_at(OrderedHashmap *h, unsigned idx) { return (struct ordered_hashmap_entry*) bucket_at(HASHMAP_BASE(h), idx); } @@ -388,13 +388,13 @@ static struct set_entry *set_bucket_at(Set *h, unsigned idx) { return (struct set_entry*) bucket_at(HASHMAP_BASE(h), idx); } -static struct ordered_hashmap_entry *bucket_at_swap(struct swap_entries *swap, unsigned idx) { +static struct ordered_hashmap_entry* bucket_at_swap(struct swap_entries *swap, unsigned idx) { return &swap->e[idx - _IDX_SWAP_BEGIN]; } /* Returns a pointer to the bucket at index idx. * Understands real indexes and swap indexes, hence "_virtual". */ -static struct hashmap_base_entry *bucket_at_virtual(HashmapBase *h, struct swap_entries *swap, +static struct hashmap_base_entry* bucket_at_virtual(HashmapBase *h, struct swap_entries *swap, unsigned idx) { if (idx < _IDX_SWAP_BEGIN) return bucket_at(h, idx); @@ -405,7 +405,7 @@ static struct hashmap_base_entry *bucket_at_virtual(HashmapBase *h, struct swap_ assert_not_reached("Invalid index"); } -static dib_raw_t *dib_raw_ptr(HashmapBase *h) { +static dib_raw_t* dib_raw_ptr(HashmapBase *h) { return (dib_raw_t*) ((uint8_t*) storage_ptr(h) + hashmap_type_info[h->type].entry_size * n_buckets(h)); } @@ -503,7 +503,7 @@ static unsigned prev_idx(HashmapBase *h, unsigned idx) { return (n_buckets(h) + idx - 1U) % n_buckets(h); } -static void *entry_value(HashmapBase *h, struct hashmap_base_entry *e) { +static void* entry_value(HashmapBase *h, struct hashmap_base_entry *e) { switch (h->type) { case HASHMAP_TYPE_PLAIN: @@ -735,7 +735,7 @@ bool _hashmap_iterate(HashmapBase *h, Iterator *i, void **value, const void **ke (idx != IDX_NIL); \ (idx) = hashmap_iterate_entry((h), &(i))) -IteratedCache *_hashmap_iterated_cache_new(HashmapBase *h) { +IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h) { IteratedCache *cache; assert(h); @@ -764,7 +764,7 @@ static void reset_direct_storage(HashmapBase *h) { memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets); } -static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) { +static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) { HashmapBase *h; const struct hashmap_type_info *hi = &hashmap_type_info[type]; bool up; @@ -872,7 +872,7 @@ static void hashmap_free_no_clear(HashmapBase *h) { free(h); } -HashmapBase *_hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) { +HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) { if (h) { _hashmap_clear(h, default_free_key, default_free_value); hashmap_free_no_clear(h); @@ -1329,7 +1329,7 @@ int hashmap_update(Hashmap *h, const void *key, void *value) { return 0; } -void *_hashmap_get(HashmapBase *h, const void *key) { +void* _hashmap_get(HashmapBase *h, const void *key) { struct hashmap_base_entry *e; unsigned hash, idx; @@ -1345,7 +1345,7 @@ void *_hashmap_get(HashmapBase *h, const void *key) { return entry_value(h, e); } -void *hashmap_get2(Hashmap *h, const void *key, void **key2) { +void* hashmap_get2(Hashmap *h, const void *key, void **key2) { struct plain_hashmap_entry *e; unsigned hash, idx; @@ -1374,7 +1374,7 @@ bool _hashmap_contains(HashmapBase *h, const void *key) { return bucket_scan(h, hash, key) != IDX_NIL; } -void *_hashmap_remove(HashmapBase *h, const void *key) { +void* _hashmap_remove(HashmapBase *h, const void *key) { struct hashmap_base_entry *e; unsigned hash, idx; void *data; @@ -1394,7 +1394,7 @@ void *_hashmap_remove(HashmapBase *h, const void *key) { return data; } -void *hashmap_remove2(Hashmap *h, const void *key, void **rkey) { +void* hashmap_remove2(Hashmap *h, const void *key, void **rkey) { struct plain_hashmap_entry *e; unsigned hash, idx; void *data; @@ -1512,7 +1512,7 @@ int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_ return 0; } -void *_hashmap_remove_value(HashmapBase *h, const void *key, void *value) { +void* _hashmap_remove_value(HashmapBase *h, const void *key, void *value) { struct hashmap_base_entry *e; unsigned hash, idx; @@ -1542,7 +1542,7 @@ static unsigned find_first_entry(HashmapBase *h) { return hashmap_iterate_entry(h, &i); } -void *_hashmap_first_key_and_value(HashmapBase *h, bool remove, void **ret_key) { +void* _hashmap_first_key_and_value(HashmapBase *h, bool remove, void **ret_key) { struct hashmap_base_entry *e; void *key, *data; unsigned idx; @@ -1717,7 +1717,7 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) { return 0; } -HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) { +HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) { HashmapBase *copy; int r; @@ -1745,7 +1745,7 @@ HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) { return copy; } -char **_hashmap_get_strv(HashmapBase *h) { +char** _hashmap_get_strv(HashmapBase *h) { char **sv; Iterator i; unsigned idx, n; @@ -1762,7 +1762,7 @@ char **_hashmap_get_strv(HashmapBase *h) { return sv; } -void *ordered_hashmap_next(OrderedHashmap *h, const void *key) { +void* ordered_hashmap_next(OrderedHashmap *h, const void *key) { struct ordered_hashmap_entry *e; unsigned hash, idx; @@ -1967,7 +1967,7 @@ int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void return 0; } -IteratedCache *iterated_cache_free(IteratedCache *cache) { +IteratedCache* iterated_cache_free(IteratedCache *cache) { if (cache) { free(cache->keys.ptr); free(cache->values.ptr); diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index c8f82b1df64..70189db8676 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -83,8 +83,8 @@ typedef struct { # define HASHMAP_DEBUG_PASS_ARGS #endif -Hashmap *_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); +Hashmap* _hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); +OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); #define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) #define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) @@ -96,39 +96,39 @@ OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DE 0; \ }) -HashmapBase *_hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value); -static inline Hashmap *hashmap_free(Hashmap *h) { +HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value); +static inline Hashmap* hashmap_free(Hashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL); } -static inline OrderedHashmap *ordered_hashmap_free(OrderedHashmap *h) { +static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL); } -static inline Hashmap *hashmap_free_free(Hashmap *h) { +static inline Hashmap* hashmap_free_free(Hashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, free); } -static inline OrderedHashmap *ordered_hashmap_free_free(OrderedHashmap *h) { +static inline OrderedHashmap* ordered_hashmap_free_free(OrderedHashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, free); } -static inline Hashmap *hashmap_free_free_key(Hashmap *h) { +static inline Hashmap* hashmap_free_free_key(Hashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), free, NULL); } -static inline OrderedHashmap *ordered_hashmap_free_free_key(OrderedHashmap *h) { +static inline OrderedHashmap* ordered_hashmap_free_free_key(OrderedHashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), free, NULL); } -static inline Hashmap *hashmap_free_free_free(Hashmap *h) { +static inline Hashmap* hashmap_free_free_free(Hashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), free, free); } -static inline OrderedHashmap *ordered_hashmap_free_free_free(OrderedHashmap *h) { +static inline OrderedHashmap* ordered_hashmap_free_free_free(OrderedHashmap *h) { return (void*) _hashmap_free(HASHMAP_BASE(h), free, free); } -IteratedCache *iterated_cache_free(IteratedCache *cache); +IteratedCache* iterated_cache_free(IteratedCache *cache); int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries); -HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS); +HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS); #define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS)) #define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS)) @@ -140,11 +140,11 @@ int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS); #define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS) -IteratedCache *_hashmap_iterated_cache_new(HashmapBase *h); -static inline IteratedCache *hashmap_iterated_cache_new(Hashmap *h) { +IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h); +static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) { return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h)); } -static inline IteratedCache *ordered_hashmap_iterated_cache_new(OrderedHashmap *h) { +static inline IteratedCache* ordered_hashmap_iterated_cache_new(OrderedHashmap *h) { return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h)); } @@ -166,7 +166,7 @@ static inline int ordered_hashmap_replace(OrderedHashmap *h, const void *key, vo return hashmap_replace(PLAIN_HASHMAP(h), key, value); } -void *_hashmap_get(HashmapBase *h, const void *key); +void* _hashmap_get(HashmapBase *h, const void *key); static inline void *hashmap_get(Hashmap *h, const void *key) { return _hashmap_get(HASHMAP_BASE(h), key); } @@ -174,7 +174,7 @@ static inline void *ordered_hashmap_get(OrderedHashmap *h, const void *key) { return _hashmap_get(HASHMAP_BASE(h), key); } -void *hashmap_get2(Hashmap *h, const void *key, void **rkey); +void* hashmap_get2(Hashmap *h, const void *key, void **rkey); static inline void *ordered_hashmap_get2(OrderedHashmap *h, const void *key, void **rkey) { return hashmap_get2(PLAIN_HASHMAP(h), key, rkey); } @@ -187,7 +187,7 @@ static inline bool ordered_hashmap_contains(OrderedHashmap *h, const void *key) return _hashmap_contains(HASHMAP_BASE(h), key); } -void *_hashmap_remove(HashmapBase *h, const void *key); +void* _hashmap_remove(HashmapBase *h, const void *key); static inline void *hashmap_remove(Hashmap *h, const void *key) { return _hashmap_remove(HASHMAP_BASE(h), key); } @@ -195,17 +195,17 @@ static inline void *ordered_hashmap_remove(OrderedHashmap *h, const void *key) { return _hashmap_remove(HASHMAP_BASE(h), key); } -void *hashmap_remove2(Hashmap *h, const void *key, void **rkey); +void* hashmap_remove2(Hashmap *h, const void *key, void **rkey); static inline void *ordered_hashmap_remove2(OrderedHashmap *h, const void *key, void **rkey) { return hashmap_remove2(PLAIN_HASHMAP(h), key, rkey); } -void *_hashmap_remove_value(HashmapBase *h, const void *key, void *value); +void* _hashmap_remove_value(HashmapBase *h, const void *key, void *value); static inline void *hashmap_remove_value(Hashmap *h, const void *key, void *value) { return _hashmap_remove_value(HASHMAP_BASE(h), key, value); } -static inline void *ordered_hashmap_remove_value(OrderedHashmap *h, const void *key, void *value) { +static inline void* ordered_hashmap_remove_value(OrderedHashmap *h, const void *key, void *value) { return hashmap_remove_value(PLAIN_HASHMAP(h), key, value); } @@ -391,13 +391,13 @@ static inline void *ordered_hashmap_first_key(OrderedHashmap *h) { }) /* no hashmap_next */ -void *ordered_hashmap_next(OrderedHashmap *h, const void *key); +void* ordered_hashmap_next(OrderedHashmap *h, const void *key); -char **_hashmap_get_strv(HashmapBase *h); -static inline char **hashmap_get_strv(Hashmap *h) { +char** _hashmap_get_strv(HashmapBase *h); +static inline char** hashmap_get_strv(Hashmap *h) { return _hashmap_get_strv(HASHMAP_BASE(h)); } -static inline char **ordered_hashmap_get_strv(OrderedHashmap *h) { +static inline char** ordered_hashmap_get_strv(OrderedHashmap *h) { return _hashmap_get_strv(HASHMAP_BASE(h)); } diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h index 2c241a808bb..26481b72d4c 100644 --- a/src/basic/ordered-set.h +++ b/src/basic/ordered-set.h @@ -54,7 +54,7 @@ static inline void* ordered_set_steal_first(OrderedSet *s) { return ordered_hashmap_steal_first((OrderedHashmap*) s); } -static inline char **ordered_set_get_strv(OrderedSet *s) { +static inline char** ordered_set_get_strv(OrderedSet *s) { return _hashmap_get_strv(HASHMAP_BASE((OrderedHashmap*) s)); } diff --git a/src/basic/set.h b/src/basic/set.h index b579e1b6dca..ff5e7b959b9 100644 --- a/src/basic/set.h +++ b/src/basic/set.h @@ -13,14 +13,14 @@ 0; \ }) -Set *_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); +Set* _set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); #define set_new(ops) _set_new(ops HASHMAP_DEBUG_SRC_ARGS) -static inline Set *set_free(Set *s) { +static inline Set* set_free(Set *s) { return (Set*) _hashmap_free(HASHMAP_BASE(s), NULL, NULL); } -static inline Set *set_free_free(Set *s) { +static inline Set* set_free_free(Set *s) { return (Set*) _hashmap_free(HASHMAP_BASE(s), free, NULL); }