Skip to content

Commit 885001e

Browse files
committed
hashmap: drop unused free func arguments in hashmap_free() and hashmap_clear()
1 parent 2d4c4d9 commit 885001e

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/basic/hashmap.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -912,24 +912,20 @@ static void hashmap_free_no_clear(HashmapBase *h) {
912912
free(h);
913913
}
914914

915-
HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) {
915+
HashmapBase* _hashmap_free(HashmapBase *h) {
916916
if (h) {
917-
_hashmap_clear(h, default_free_key, default_free_value);
917+
_hashmap_clear(h);
918918
hashmap_free_no_clear(h);
919919
}
920920

921921
return NULL;
922922
}
923923

924-
void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) {
925-
free_func_t free_key, free_value;
924+
void _hashmap_clear(HashmapBase *h) {
926925
if (!h)
927926
return;
928927

929-
free_key = h->hash_ops->free_key ?: default_free_key;
930-
free_value = h->hash_ops->free_value ?: default_free_value;
931-
932-
if (free_key || free_value) {
928+
if (h->hash_ops->free_key || h->hash_ops->free_value) {
933929

934930
/* If destructor calls are defined, let's destroy things defensively: let's take the item out of the
935931
* 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
941937

942938
v = _hashmap_first_key_and_value(h, true, &k);
943939

944-
if (free_key)
945-
free_key(k);
940+
if (h->hash_ops->free_key)
941+
h->hash_ops->free_key(k);
946942

947-
if (free_value)
948-
free_value(v);
943+
if (h->hash_ops->free_value)
944+
h->hash_ops->free_value(v);
949945
}
950946
}
951947

@@ -1780,7 +1776,7 @@ HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
17801776
}
17811777

17821778
if (r < 0)
1783-
return _hashmap_free(copy, NULL, NULL);
1779+
return _hashmap_free(copy);
17841780

17851781
return copy;
17861782
}

src/basic/hashmap.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DE
9393
#define ordered_hashmap_free_and_replace(a, b) \
9494
free_and_replace_full(a, b, ordered_hashmap_free)
9595

96-
HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value);
96+
HashmapBase* _hashmap_free(HashmapBase *h);
9797
static inline Hashmap* hashmap_free(Hashmap *h) {
98-
return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL);
98+
return (void*) _hashmap_free(HASHMAP_BASE(h));
9999
}
100100
static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) {
101-
return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL);
101+
return (void*) _hashmap_free(HASHMAP_BASE(h));
102102
}
103103

104104
IteratedCache* iterated_cache_free(IteratedCache *cache);
@@ -266,12 +266,12 @@ static inline bool ordered_hashmap_iterate(OrderedHashmap *h, Iterator *i, void
266266
return _hashmap_iterate(HASHMAP_BASE(h), i, value, key);
267267
}
268268

269-
void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value);
269+
void _hashmap_clear(HashmapBase *h);
270270
static inline void hashmap_clear(Hashmap *h) {
271-
_hashmap_clear(HASHMAP_BASE(h), NULL, NULL);
271+
_hashmap_clear(HASHMAP_BASE(h));
272272
}
273273
static inline void ordered_hashmap_clear(OrderedHashmap *h) {
274-
_hashmap_clear(HASHMAP_BASE(h), NULL, NULL);
274+
_hashmap_clear(HASHMAP_BASE(h));
275275
}
276276

277277
/*

src/basic/set.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Set* _set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
1212
#define set_new(ops) _set_new(ops HASHMAP_DEBUG_SRC_ARGS)
1313

1414
static inline Set* set_free(Set *s) {
15-
return (Set*) _hashmap_free(HASHMAP_BASE(s), NULL, NULL);
15+
return (Set*) _hashmap_free(HASHMAP_BASE(s));
1616
}
1717

1818
#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) {
7171
}
7272

7373
static inline void set_clear(Set *s) {
74-
_hashmap_clear(HASHMAP_BASE(s), NULL, NULL);
74+
_hashmap_clear(HASHMAP_BASE(s));
7575
}
7676

7777
static inline void *set_steal_first(Set *s) {

0 commit comments

Comments
 (0)