From ab73a9d119240b0b908ccb9edd19b8e536ce29b9 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 3 Jul 2014 00:22:11 +0200 Subject: hashmap: add simplified hashmap_get_from_hash() API Hashmap entries are typically looked up by just a key. The hashmap_get() API expects an initialized entry structure instead, to support compound keys. This flexibility is currently only needed by find_dir_entry() in name-hash.c (and compat/win32/fscache.c in the msysgit fork). All other (currently five) call sites of hashmap_get() have to set up a near emtpy entry structure, resulting in duplicate code like this: struct hashmap_entry keyentry; hashmap_entry_init(&keyentry, hash(key)); return hashmap_get(map, &keyentry, key); Add a hashmap_get_from_hash() API that allows hashmap lookups by just specifying the key and its hash code, i.e.: return hashmap_get_from_hash(map, hash(key), key); Signed-off-by: Karsten Blees Signed-off-by: Junio C Hamano --- builtin/describe.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/describe.c b/builtin/describe.c index 57e84c8ae6..ee6a3b998f 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -58,9 +58,7 @@ static int commit_name_cmp(const struct commit_name *cn1, static inline struct commit_name *find_commit_name(const unsigned char *peeled) { - struct commit_name key; - hashmap_entry_init(&key, sha1hash(peeled)); - return hashmap_get(&names, &key, peeled); + return hashmap_get_from_hash(&names, sha1hash(peeled), peeled); } static int replace_name(struct commit_name *e, -- cgit v1.2.3