From 885001ed5d4953bc5758f52d437147aa0768f881 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 11 Apr 2025 12:11:49 +0900 Subject: [PATCH] hashmap: drop unused free func arguments in hashmap_free() and hashmap_clear() --- src/basic/hashmap.c | 22 +++++++++------------- src/basic/hashmap.h | 12 ++++++------ src/basic/set.h | 4 ++-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index a547b8c31c..3d6d1f26b5 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -912,24 +912,20 @@ 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) { if (h) { - _hashmap_clear(h, default_free_key, default_free_value); + _hashmap_clear(h); hashmap_free_no_clear(h); } return NULL; } -void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) { - free_func_t free_key, free_value; +void _hashmap_clear(HashmapBase *h) { if (!h) return; - free_key = h->hash_ops->free_key ?: default_free_key; - free_value = h->hash_ops->free_value ?: default_free_value; - - if (free_key || free_value) { + if (h->hash_ops->free_key || h->hash_ops->free_value) { /* If destructor calls are defined, let's destroy things defensively: let's take the item out of the * hash table, and only then call the destructor functions. If these destructors then try to unregister @@ -941,11 +937,11 @@ void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t de v = _hashmap_first_key_and_value(h, true, &k); - if (free_key) - free_key(k); + if (h->hash_ops->free_key) + h->hash_ops->free_key(k); - if (free_value) - free_value(v); + if (h->hash_ops->free_value) + h->hash_ops->free_value(v); } } @@ -1780,7 +1776,7 @@ HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) { } if (r < 0) - return _hashmap_free(copy, NULL, NULL); + return _hashmap_free(copy); return copy; } diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index c577bd6c22..eb810e1e07 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -93,12 +93,12 @@ OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DE #define ordered_hashmap_free_and_replace(a, b) \ free_and_replace_full(a, b, ordered_hashmap_free) -HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value); +HashmapBase* _hashmap_free(HashmapBase *h); static inline Hashmap* hashmap_free(Hashmap *h) { - return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL); + return (void*) _hashmap_free(HASHMAP_BASE(h)); } static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) { - return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL); + return (void*) _hashmap_free(HASHMAP_BASE(h)); } IteratedCache* iterated_cache_free(IteratedCache *cache); @@ -266,12 +266,12 @@ static inline bool ordered_hashmap_iterate(OrderedHashmap *h, Iterator *i, void return _hashmap_iterate(HASHMAP_BASE(h), i, value, key); } -void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value); +void _hashmap_clear(HashmapBase *h); static inline void hashmap_clear(Hashmap *h) { - _hashmap_clear(HASHMAP_BASE(h), NULL, NULL); + _hashmap_clear(HASHMAP_BASE(h)); } static inline void ordered_hashmap_clear(OrderedHashmap *h) { - _hashmap_clear(HASHMAP_BASE(h), NULL, NULL); + _hashmap_clear(HASHMAP_BASE(h)); } /* diff --git a/src/basic/set.h b/src/basic/set.h index 0392531e16..6e6b386687 100644 --- a/src/basic/set.h +++ b/src/basic/set.h @@ -12,7 +12,7 @@ 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) { - return (Set*) _hashmap_free(HASHMAP_BASE(s), NULL, NULL); + return (Set*) _hashmap_free(HASHMAP_BASE(s)); } #define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s) HASHMAP_DEBUG_SRC_ARGS)) @@ -71,7 +71,7 @@ static inline bool set_iterate(const Set *s, Iterator *i, void **value) { } static inline void set_clear(Set *s) { - _hashmap_clear(HASHMAP_BASE(s), NULL, NULL); + _hashmap_clear(HASHMAP_BASE(s)); } static inline void *set_steal_first(Set *s) {