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:
Elijah Newren
2020-11-02 18:55:05 +00:00
committed by Junio C Hamano
parent 33f20d8217
commit 6da1a25814
22 changed files with 63 additions and 53 deletions

8
dir.c
View File

@ -817,8 +817,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
clear_hashmaps:
warning(_("disabling cone pattern matching"));
hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent);
hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent);
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
pl->use_cone_patterns = 0;
}
@ -921,8 +921,8 @@ void clear_pattern_list(struct pattern_list *pl)
free(pl->patterns[i]);
free(pl->patterns);
free(pl->filebuf);
hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent);
hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent);
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
memset(pl, 0, sizeof(*pl));
}