Skip to content

Commit 6da1a25

Browse files
newrengitster
authored andcommitted
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/[email protected]/ Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33f20d8 commit 6da1a25

22 files changed

+63
-53
lines changed

add-interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
557557
if (ps)
558558
clear_pathspec(&rev.prune_data);
559559
}
560-
hashmap_free_entries(&s.file_map, struct pathname_entry, ent);
560+
hashmap_clear_and_free(&s.file_map, struct pathname_entry, ent);
561561
if (unmerged_count)
562562
*unmerged_count = s.unmerged_count;
563563
if (binary_count)

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static void get_fingerprint(struct fingerprint *result,
435435

436436
static void free_fingerprint(struct fingerprint *f)
437437
{
438-
hashmap_free(&f->map);
438+
hashmap_clear(&f->map);
439439
free(f->entries);
440440
}
441441

bloom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
287287
}
288288

289289
cleanup:
290-
hashmap_free_entries(&pathmap, struct pathmap_hash_entry, entry);
290+
hashmap_clear_and_free(&pathmap, struct pathmap_hash_entry, entry);
291291
} else {
292292
for (i = 0; i < diff_queued_diff.nr; i++)
293293
diff_free_filepair(diff_queued_diff.queue[i]);

builtin/fetch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void find_non_local_tags(const struct ref *refs,
393393
item = refname_hash_add(&remote_refs, ref->name, &ref->old_oid);
394394
string_list_insert(&remote_refs_list, ref->name);
395395
}
396-
hashmap_free_entries(&existing_refs, struct refname_hash_entry, ent);
396+
hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent);
397397

398398
/*
399399
* We may have a final lightweight tag that needs to be
@@ -428,7 +428,7 @@ static void find_non_local_tags(const struct ref *refs,
428428
**tail = rm;
429429
*tail = &rm->next;
430430
}
431-
hashmap_free_entries(&remote_refs, struct refname_hash_entry, ent);
431+
hashmap_clear_and_free(&remote_refs, struct refname_hash_entry, ent);
432432
string_list_clear(&remote_refs_list, 0);
433433
oidset_clear(&fetch_oids);
434434
}
@@ -573,7 +573,7 @@ static struct ref *get_ref_map(struct remote *remote,
573573
}
574574
}
575575
if (existing_refs_populated)
576-
hashmap_free_entries(&existing_refs, struct refname_hash_entry, ent);
576+
hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent);
577577

578578
return ref_map;
579579
}

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static void strset_clear(struct strset *ss)
220220
{
221221
if (!ss->map.table)
222222
return;
223-
hashmap_free_entries(&ss->map, struct strset_item, ent);
223+
hashmap_clear_and_free(&ss->map, struct strset_item, ent);
224224
}
225225

226226
static void insert_records_from_trailers(struct shortlog *log,

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ void git_configset_clear(struct config_set *cs)
19631963
free(entry->key);
19641964
string_list_clear(&entry->value_list, 1);
19651965
}
1966-
hashmap_free_entries(&cs->config_hash, struct config_set_element, ent);
1966+
hashmap_clear_and_free(&cs->config_hash, struct config_set_element, ent);
19671967
cs->hash_initialized = 0;
19681968
free(cs->list.items);
19691969
cs->list.nr = 0;

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6289,9 +6289,9 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
62896289
if (o->color_moved == COLOR_MOVED_ZEBRA_DIM)
62906290
dim_moved_lines(o);
62916291

6292-
hashmap_free_entries(&add_lines, struct moved_entry,
6292+
hashmap_clear_and_free(&add_lines, struct moved_entry,
62936293
ent);
6294-
hashmap_free_entries(&del_lines, struct moved_entry,
6294+
hashmap_clear_and_free(&del_lines, struct moved_entry,
62956295
ent);
62966296
}
62976297

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static int find_exact_renames(struct diff_options *options)
407407
renames += find_identical_files(&file_table, i, options);
408408

409409
/* Free the hash data structure and entries */
410-
hashmap_free_entries(&file_table, struct file_similarity, entry);
410+
hashmap_clear_and_free(&file_table, struct file_similarity, entry);
411411

412412
return renames;
413413
}

dir.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
817817

818818
clear_hashmaps:
819819
warning(_("disabling cone pattern matching"));
820-
hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent);
821-
hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent);
820+
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
821+
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
822822
pl->use_cone_patterns = 0;
823823
}
824824

@@ -921,8 +921,8 @@ void clear_pattern_list(struct pattern_list *pl)
921921
free(pl->patterns[i]);
922922
free(pl->patterns);
923923
free(pl->filebuf);
924-
hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent);
925-
hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent);
924+
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
925+
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
926926

927927
memset(pl, 0, sizeof(*pl));
928928
}

hashmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void free_individual_entries(struct hashmap *map, ssize_t entry_offset)
183183
while ((e = hashmap_iter_next(&iter)))
184184
/*
185185
* like container_of, but using caller-calculated
186-
* offset (caller being hashmap_free_entries)
186+
* offset (caller being hashmap_clear_and_free)
187187
*/
188188
free((char *)e - entry_offset);
189189
}
@@ -199,11 +199,11 @@ void hashmap_partial_clear_(struct hashmap *map, ssize_t entry_offset)
199199
map->private_size = 0;
200200
}
201201

202-
void hashmap_free_(struct hashmap *map, ssize_t entry_offset)
202+
void hashmap_clear_(struct hashmap *map, ssize_t entry_offset)
203203
{
204204
if (!map || !map->table)
205205
return;
206-
if (entry_offset >= 0) /* called by hashmap_free_entries */
206+
if (entry_offset >= 0) /* called by hashmap_clear_and_free */
207207
free_individual_entries(map, entry_offset);
208208
free(map->table);
209209
memset(map, 0, sizeof(*map));

0 commit comments

Comments
 (0)