mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
hashmap: provide deallocation function names
hashmap_free(), hashmap_free_entries(), and hashmap_free_() have existed
for a while, but aren't necessarily the clearest names, especially with
hashmap_partial_clear() being added to the mix and lazy-initialization
now being supported. Peff suggested we adopt the following names[1]:
- hashmap_clear() - remove all entries and de-allocate any
hashmap-specific data, but be ready for reuse
- hashmap_clear_and_free() - ditto, but free the entries themselves
- hashmap_partial_clear() - remove all entries but don't deallocate
table
- hashmap_partial_clear_and_free() - ditto, but free the entries
This patch provides the new names and converts all existing callers over
to the new naming scheme.
[1] https://lore.kernel.org/git/20201030125059.GA3277724@coredump.intra.peff.net/
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
33f20d8217
commit
6da1a25814
@@ -183,7 +183,7 @@ static void free_individual_entries(struct hashmap *map, ssize_t entry_offset)
|
||||
while ((e = hashmap_iter_next(&iter)))
|
||||
/*
|
||||
* like container_of, but using caller-calculated
|
||||
* offset (caller being hashmap_free_entries)
|
||||
* offset (caller being hashmap_clear_and_free)
|
||||
*/
|
||||
free((char *)e - entry_offset);
|
||||
}
|
||||
@@ -199,11 +199,11 @@ void hashmap_partial_clear_(struct hashmap *map, ssize_t entry_offset)
|
||||
map->private_size = 0;
|
||||
}
|
||||
|
||||
void hashmap_free_(struct hashmap *map, ssize_t entry_offset)
|
||||
void hashmap_clear_(struct hashmap *map, ssize_t entry_offset)
|
||||
{
|
||||
if (!map || !map->table)
|
||||
return;
|
||||
if (entry_offset >= 0) /* called by hashmap_free_entries */
|
||||
if (entry_offset >= 0) /* called by hashmap_clear_and_free */
|
||||
free_individual_entries(map, entry_offset);
|
||||
free(map->table);
|
||||
memset(map, 0, sizeof(*map));
|
||||
|
||||
Reference in New Issue
Block a user