+1
-1
index 555c4abf32..a14c0feaa2 100644
--- a/add-interactive.c
+++ b/add-interactive.c
if (ps)
clear_pathspec(&rev.prune_data);
}
- hashmap_free_entries(&s.file_map, struct pathname_entry, ent);
+ hashmap_clear_and_free(&s.file_map, struct pathname_entry, ent);
if (unmerged_count)
*unmerged_count = s.unmerged_count;
if (binary_count)
+1
-1
index 686845b2b4..229beb6452 100644
--- a/blame.c
+++ b/blame.c
static void free_fingerprint(struct fingerprint *f)
{
- hashmap_free(&f->map);
+ hashmap_clear(&f->map);
free(f->entries);
}
+1
-1
index 68c73200a5..719c313a1c 100644
--- a/bloom.c
+++ b/bloom.c
}
cleanup:
- hashmap_free_entries(&pathmap, struct pathmap_hash_entry, entry);
+ hashmap_clear_and_free(&pathmap, struct pathmap_hash_entry, entry);
} else {
for (i = 0; i < diff_queued_diff.nr; i++)
diff_free_filepair(diff_queued_diff.queue[i]);
+3
-3
index f9c3c49f14..ecf8537605 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
item = refname_hash_add(&remote_refs, ref->name, &ref->old_oid);
string_list_insert(&remote_refs_list, ref->name);
}
- hashmap_free_entries(&existing_refs, struct refname_hash_entry, ent);
+ hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent);
/*
* We may have a final lightweight tag that needs to be
**tail = rm;
*tail = &rm->next;
}
- hashmap_free_entries(&remote_refs, struct refname_hash_entry, ent);
+ hashmap_clear_and_free(&remote_refs, struct refname_hash_entry, ent);
string_list_clear(&remote_refs_list, 0);
oidset_clear(&fetch_oids);
}
}
}
if (existing_refs_populated)
- hashmap_free_entries(&existing_refs, struct refname_hash_entry, ent);
+ hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent);
return ref_map;
}
+1
-1
index 0a5c4968f6..83f0a739b4 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
{
if (!ss->map.table)
return;
- hashmap_free_entries(&ss->map, struct strset_item, ent);
+ hashmap_clear_and_free(&ss->map, struct strset_item, ent);
}
static void insert_records_from_trailers(struct shortlog *log,
+1
-1
index 2bdff4457b..8f324ed3a6 100644
--- a/config.c
+++ b/config.c
free(entry->key);
string_list_clear(&entry->value_list, 1);
}
- hashmap_free_entries(&cs->config_hash, struct config_set_element, ent);
+ hashmap_clear_and_free(&cs->config_hash, struct config_set_element, ent);
cs->hash_initialized = 0;
free(cs->list.items);
cs->list.nr = 0;
+2
-2
index 2bb2f8f57e..8e0e59f5cf 100644
--- a/diff.c
+++ b/diff.c
if (o->color_moved == COLOR_MOVED_ZEBRA_DIM)
dim_moved_lines(o);
- hashmap_free_entries(&add_lines, struct moved_entry,
+ hashmap_clear_and_free(&add_lines, struct moved_entry,
ent);
- hashmap_free_entries(&del_lines, struct moved_entry,
+ hashmap_clear_and_free(&del_lines, struct moved_entry,
ent);
}
+1
-1
index 99e63e90f8..d367a6d244 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
renames += find_identical_files(&file_table, i, options);
/* Free the hash data structure and entries */
- hashmap_free_entries(&file_table, struct file_similarity, entry);
+ hashmap_clear_and_free(&file_table, struct file_similarity, entry);
return renames;
}
+4
-4
index 78387110e6..161dce121e 100644
--- a/dir.c
+++ b/dir.c
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;
}
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));
}
+3
-3
index 922ed07954..5009471800 100644
--- a/hashmap.c
+++ b/hashmap.c
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);
}
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));
+27
-17
index e9430d582a..7251687d73 100644
--- a/hashmap.h
+++ b/hashmap.h
* }
*
* if (!strcmp("end", action)) {
- * hashmap_free_entries(&map, struct long2string, ent);
+ * hashmap_clear_and_free(&map, struct long2string, ent);
* break;
* }
* }
/* internal functions for clearing or freeing hashmap */
void hashmap_partial_clear_(struct hashmap *map, ssize_t offset);
-void hashmap_free_(struct hashmap *map, ssize_t offset);
+void hashmap_clear_(struct hashmap *map, ssize_t offset);
/*
* Frees a hashmap structure and allocated memory for the table, but does not
* free(e->somefield);
* free(e);
* }
- * hashmap_free(map);
+ * hashmap_clear(map);
*
* instead of
*
* hashmap_for_each_entry(map, hashmap_iter, e, hashmap_entry_name) {
* free(e->somefield);
* }
- * hashmap_free_entries(map, struct my_entry_struct, hashmap_entry_name);
+ * hashmap_clear_and_free(map, struct my_entry_struct, hashmap_entry_name);
*
* to avoid the implicit extra loop over the entries. However, if there are
* no special fields in your entry that need to be freed beyond the entry
* itself, it is probably simpler to avoid the explicit loop and just call
- * hashmap_free_entries().
+ * hashmap_clear_and_free().
*/
-#define hashmap_free(map) hashmap_free_(map, -1)
+#define hashmap_clear(map) hashmap_clear_(map, -1)
/*
- * Basically the same as calling hashmap_free() followed by hashmap_init(),
- * but doesn't incur the overhead of deallocating and reallocating
- * map->table; it leaves map->table allocated and the same size but zeroes
- * it out so it's ready for use again as an empty map. As with
- * hashmap_free(), you may need to free the entries yourself before calling
- * this function.
+ * Similar to hashmap_clear(), except that the table is no deallocated; it
+ * is merely zeroed out but left the same size as before. If the hashmap
+ * will be reused, this avoids the overhead of deallocating and
+ * reallocating map->table. As with hashmap_clear(), you may need to free
+ * the entries yourself before calling this function.
*/
#define hashmap_partial_clear(map) hashmap_partial_clear_(map, -1)
/*
- * Frees @map and all entries. @type is the struct type of the entry
- * where @member is the hashmap_entry struct used to associate with @map.
+ * Similar to hashmap_clear() but also frees all entries. @type is the
+ * struct type of the entry where @member is the hashmap_entry struct used
+ * to associate with @map.
*
- * See usage note above hashmap_free().
+ * See usage note above hashmap_clear().
*/
-#define hashmap_free_entries(map, type, member) \
- hashmap_free_(map, offsetof(type, member));
+#define hashmap_clear_and_free(map, type, member) \
+ hashmap_clear_(map, offsetof(type, member))
+
+/*
+ * Similar to hashmap_partial_clear() but also frees all entries. @type is
+ * the struct type of the entry where @member is the hashmap_entry struct
+ * used to associate with @map.
+ *
+ * See usage note above hashmap_clear().
+ */
+#define hashmap_partial_clear_and_free(map, type, member) \
+ hashmap_partial_clear_(map, offsetof(type, member))
/* hashmap_entry functions */
+3
-3
index d0214335a7..f736a0f632 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
free(e->target_file);
string_list_clear(&e->source_files, 0);
}
- hashmap_free_entries(&collisions, struct collision_entry, ent);
+ hashmap_clear_and_free(&collisions, struct collision_entry, ent);
return renames;
}
strbuf_release(&e->new_dir);
/* possible_new_dirs already cleared in get_directory_renames */
}
- hashmap_free_entries(dir_renames, struct dir_rename_entry, ent);
+ hashmap_clear_and_free(dir_renames, struct dir_rename_entry, ent);
free(dir_renames);
free(pairs->queue);
string_list_clear(entries, 1);
free(entries);
- hashmap_free_entries(&opt->priv->current_file_dir_set,
+ hashmap_clear_and_free(&opt->priv->current_file_dir_set,
struct path_hashmap_entry, e);
if (clean < 0) {
+2
-2
index fb526a3775..5d3c7b12c1 100644
--- a/name-hash.c
+++ b/name-hash.c
return;
istate->name_hash_initialized = 0;
- hashmap_free(&istate->name_hash);
- hashmap_free_entries(&istate->dir_hash, struct dir_entry, ent);
+ hashmap_clear(&istate->name_hash);
+ hashmap_clear_and_free(&istate->dir_hash, struct dir_entry, ent);
}
+1
-1
index 3257518656..b8406409d5 100644
--- a/object.c
+++ b/object.c
close_object_store(o);
o->packed_git = NULL;
- hashmap_free(&o->pack_map);
+ hashmap_clear(&o->pack_map);
}
void parsed_object_pool_clear(struct parsed_object_pool *o)
+1
-1
index 423aa014a3..286a04a53c 100644
--- a/oidmap.c
+++ b/oidmap.c
return;
/* TODO: make oidmap itself not depend on struct layouts */
- hashmap_free_(&map->map, free_entries ? 0 : -1);
+ hashmap_clear_(&map->map, free_entries ? 0 : -1);
}
void *oidmap_get(const struct oidmap *map, const struct object_id *key)
+1
-1
index 12aa6d494b..21973e4933 100644
--- a/patch-ids.c
+++ b/patch-ids.c
int free_patch_ids(struct patch_ids *ids)
{
- hashmap_free_entries(&ids->patches, struct patch_id, ent);
+ hashmap_clear_and_free(&ids->patches, struct patch_id, ent);
return 0;
}
+1
-1
index 24dc435e48..befeecae44 100644
--- a/range-diff.c
+++ b/range-diff.c
}
}
- hashmap_free(&map);
+ hashmap_clear(&map);
}
static void diffsize_consume(void *data, char *line, unsigned long len)
+1
-1
index c62f6b4822..5e66b8cd76 100644
--- a/ref-filter.c
+++ b/ref-filter.c
used_atom_cnt = 0;
if (ref_to_worktree_map.worktrees) {
- hashmap_free_entries(&(ref_to_worktree_map.map),
+ hashmap_clear_and_free(&(ref_to_worktree_map.map),
struct ref_to_worktree_entry, ent);
free_worktrees(ref_to_worktree_map.worktrees);
ref_to_worktree_map.worktrees = NULL;
+1
-1
index aa62212040..f27649d45d 100644
--- a/revision.c
+++ b/revision.c
free(entry->path);
}
- hashmap_free_entries(map, struct path_and_oids_entry, ent);
+ hashmap_clear_and_free(map, struct path_and_oids_entry, ent);
}
static void paths_and_oids_insert(struct hashmap *map,
+2
-2
index 00acb12496..23a09c3e7a 100644
--- a/sequencer.c
+++ b/sequencer.c
oidmap_free(&commit2todo, 1);
oidmap_free(&state.commit2label, 1);
- hashmap_free_entries(&state.labels, struct labels_entry, entry);
+ hashmap_clear_and_free(&state.labels, struct labels_entry, entry);
strbuf_release(&state.buf);
return 0;
for (i = 0; i < todo_list->nr; i++)
free(subjects[i]);
free(subjects);
- hashmap_free_entries(&subject2item, struct subject2item_entry, entry);
+ hashmap_clear_and_free(&subject2item, struct subject2item_entry, entry);
clear_commit_todo_item(&commit_todo);
+2
-2
index c569e22aa3..f502505566 100644
--- a/submodule-config.c
+++ b/submodule-config.c
ent /* member name */)
free_one_config(entry);
- hashmap_free_entries(&cache->for_path, struct submodule_entry, ent);
- hashmap_free_entries(&cache->for_name, struct submodule_entry, ent);
+ hashmap_clear_and_free(&cache->for_path, struct submodule_entry, ent);
+ hashmap_clear_and_free(&cache->for_name, struct submodule_entry, ent);
cache->initialized = 0;
cache->gitmodules_read = 0;
}
+3
-3
index f38706216f..2475663b49 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
hashmap_add(&map, &entries[i]->ent);
}
- hashmap_free(&map);
+ hashmap_clear(&map);
}
} else {
/* test map lookups */
}
}
- hashmap_free(&map);
+ hashmap_clear(&map);
}
}
}
strbuf_release(&line);
- hashmap_free_entries(&map, struct test_entry, ent);
+ hashmap_clear_and_free(&map, struct test_entry, ent);
return 0;
}