]> git.ipfire.org Git - thirdparty/git.git/blobdiff - hashmap.c
midx: add progress to expire_midx_packs
[thirdparty/git.git] / hashmap.c
index 1b60f97cf20344dd798e64305522eab109156875..39c13110bc32f05f0cbb4ec1cf22bdc6ea6995b2 100644 (file)
--- a/hashmap.c
+++ b/hashmap.c
@@ -171,16 +171,21 @@ void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function,
        map->do_count_items = 1;
 }
 
-void hashmap_free(struct hashmap *map, int free_entries)
+void hashmap_free_(struct hashmap *map, ssize_t entry_offset)
 {
        if (!map || !map->table)
                return;
-       if (free_entries) {
+       if (entry_offset >= 0) { /* called by hashmap_free_entries */
                struct hashmap_iter iter;
                struct hashmap_entry *e;
+
                hashmap_iter_init(map, &iter);
                while ((e = hashmap_iter_next(&iter)))
-                       free(e);
+                       /*
+                        * like container_of, but using caller-calculated
+                        * offset (caller being hashmap_free_entries)
+                        */
+                       free((char *)e - entry_offset);
        }
        free(map->table);
        memset(map, 0, sizeof(*map));
@@ -306,7 +311,7 @@ const void *memintern(const void *data, size_t len)
        /* lookup interned string in pool */
        hashmap_entry_init(&key.ent, memhash(data, len));
        key.len = len;
-       e = hashmap_get_entry(&map, &key, data, struct pool_entry, ent);
+       e = hashmap_get_entry(&map, &key, ent, data);
        if (!e) {
                /* not found: create it */
                FLEX_ALLOC_MEM(e, data, data, len);