git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 01/10] attr.c: drop hashmap_cmp_fn cast

From
Stefan Beller <sbeller@google.com>
Date
Jul 1, 2017, 00:28 UTC
Message-ID
<20170701002838.22785-2-sbeller@google.com>
In-Reply-To
<20170701002838.22785-1-sbeller@google.com>

MAke the code more readable and less error prone by avoiding the cast of the compare function pointer in hashmap_init, but instead have the correctly named void pointers to casted to the specific data structure.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 attr.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/attr.c b/attr.c
index 56961f0236..2f49151736 100644
--- a/attr.c
+++ b/attr.c
@@ -76,18 +76,20 @@ struct attr_hash_entry {
 };
 
 /* attr_hashmap comparison function */
-static int attr_hash_entry_cmp(void *unused_cmp_data,
-			       const struct attr_hash_entry *a,
-			       const struct attr_hash_entry *b,
-			       void *unused_keydata)
+static int attr_hash_entry_cmp(const void *unused_cmp_data,
+			       const void *entry,
+			       const void *entry_or_key,
+			       const void *unused_keydata)
 {
+	const struct attr_hash_entry *a = entry;
+	const struct attr_hash_entry *b = entry_or_key;
 	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, (hashmap_cmp_fn) attr_hash_entry_cmp, NULL, 0);
+	hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
 }
 
 /*
-- 
2.13.0.31.g9b732c453e
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 12 in “Friday night special: hash map cleanup”
  1. 00/10 Friday night special: hash map cleanupStefan Beller, Jul 1, 2017
  2. 01/10 attr.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  3. 02/10 builtin/difftool.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  4. 03/10 builtin/describe: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  5. 04/10 config.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  6. 09/10 name-hash.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  7. 10/10 t/helper/test-hashmap: use custom data instead of duplicate cmp functionsStefan Beller, Jul 1, 2017
  8. 08/10 submodule-config.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  9. 06/10 patch-ids.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  10. 05/10 convert/sub-process: drop cast to hashmap_cmp_fnStefan Beller, Jul 1, 2017
  11. 07/10 remote.c: drop hashmap_cmp_fn castStefan Beller, Jul 1, 2017
  12. Junio C HamanoJul 5, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.