summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2020-11-11 20:02:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-11 20:55:27 (GMT)
commitb19315d8ab46ae50410dba9228a4c08ae5c73e38 (patch)
treef473f15041b2f515f50aacdda428825e884eb18d /attr.c
parent23a276a9c4c8945aadbc323e12c970816eb43c27 (diff)
downloadgit-b19315d8ab46ae50410dba9228a4c08ae5c73e38.zip
git-b19315d8ab46ae50410dba9228a4c08ae5c73e38.tar.gz
git-b19315d8ab46ae50410dba9228a4c08ae5c73e38.tar.bz2
Use new HASHMAP_INIT macro to simplify hashmap initialization
Now that hashamp has lazy initialization and a HASHMAP_INIT macro, hashmaps allocated on the stack can be initialized without a call to hashmap_init() and in some cases makes the code a bit shorter. Convert some callsites over to take advantage of this. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/attr.c b/attr.c
index a826b2e..4ef85d6 100644
--- a/attr.c
+++ b/attr.c
@@ -52,13 +52,6 @@ static inline void hashmap_unlock(struct attr_hashmap *map)
pthread_mutex_unlock(&map->mutex);
}
-/*
- * The global dictionary of all interned attributes. This
- * is a singleton object which is shared between threads.
- * Access to this dictionary must be surrounded with a mutex.
- */
-static struct attr_hashmap g_attr_hashmap;
-
/* The container for objects stored in "struct attr_hashmap" */
struct attr_hash_entry {
struct hashmap_entry ent;
@@ -80,11 +73,14 @@ static int attr_hash_entry_cmp(const void *unused_cmp_data,
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
}
-/* Initialize an 'attr_hashmap' object */
-static void attr_hashmap_init(struct attr_hashmap *map)
-{
- hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
-}
+/*
+ * The global dictionary of all interned attributes. This
+ * is a singleton object which is shared between threads.
+ * Access to this dictionary must be surrounded with a mutex.
+ */
+static struct attr_hashmap g_attr_hashmap = {
+ HASHMAP_INIT(attr_hash_entry_cmp, NULL)
+};
/*
* Retrieve the 'value' stored in a hashmap given the provided 'key'.
@@ -96,9 +92,6 @@ static void *attr_hashmap_get(struct attr_hashmap *map,
struct attr_hash_entry k;
struct attr_hash_entry *e;
- if (!map->map.tablesize)
- attr_hashmap_init(map);
-
hashmap_entry_init(&k.ent, memhash(key, keylen));
k.key = key;
k.keylen = keylen;
@@ -114,9 +107,6 @@ static void attr_hashmap_add(struct attr_hashmap *map,
{
struct attr_hash_entry *e;
- if (!map->map.tablesize)
- attr_hashmap_init(map);
-
e = xmalloc(sizeof(struct attr_hash_entry));
hashmap_entry_init(&e->ent, memhash(key, keylen));
e->key = key;