]> git.ipfire.org Git - thirdparty/git.git/blobdiff - hashmap.c
Merge branch 'sg/tests-prereq'
[thirdparty/git.git] / hashmap.c
index bb7c9979b8d7e459439516237c747a08f000ace3..5009471800e8c61b50bfd670a7714daaa26a01c7 100644 (file)
--- a/hashmap.c
+++ b/hashmap.c
@@ -174,22 +174,37 @@ void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function,
        map->do_count_items = 1;
 }
 
-void hashmap_free_(struct hashmap *map, ssize_t entry_offset)
+static void free_individual_entries(struct hashmap *map, ssize_t entry_offset)
+{
+       struct hashmap_iter iter;
+       struct hashmap_entry *e;
+
+       hashmap_iter_init(map, &iter);
+       while ((e = hashmap_iter_next(&iter)))
+               /*
+                * like container_of, but using caller-calculated
+                * offset (caller being hashmap_clear_and_free)
+                */
+               free((char *)e - entry_offset);
+}
+
+void hashmap_partial_clear_(struct hashmap *map, ssize_t entry_offset)
 {
        if (!map || !map->table)
                return;
-       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)))
-                       /*
-                        * like container_of, but using caller-calculated
-                        * offset (caller being hashmap_free_entries)
-                        */
-                       free((char *)e - entry_offset);
-       }
+       if (entry_offset >= 0)  /* called by hashmap_clear_entries */
+               free_individual_entries(map, entry_offset);
+       memset(map->table, 0, map->tablesize * sizeof(struct hashmap_entry *));
+       map->shrink_at = 0;
+       map->private_size = 0;
+}
+
+void hashmap_clear_(struct hashmap *map, ssize_t entry_offset)
+{
+       if (!map || !map->table)
+               return;
+       if (entry_offset >= 0)  /* called by hashmap_clear_and_free */
+               free_individual_entries(map, entry_offset);
        free(map->table);
        memset(map, 0, sizeof(*map));
 }