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

[PATCH 1/5] name-hash: eliminate duplicate memihash call

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 14, 2017, 11:31 UTC
Message-ID
<7fb6e739dde4dd733524708bae57f0e6e75f61c9.1487071883.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1487071883.git.johannes.schindelin@gmx.de>
From: Jeff Hostetler <jeffhost@microsoft.com>

The existing code called memihash() to pass to the find_dir_entry() function, and if not found, called memihash() again to pass to the hashmap_add() function. Remove that duplicate memihash() call in hash_dir_entry().

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 name-hash.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/name-hash.c b/name-hash.c
index 6d9f23e9325..ad0bc0cef73 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -23,15 +23,21 @@ static int dir_entry_cmp(const struct dir_entry *e1,
 			name ? name : e2->name, e1->namelen);
 }
 
-static struct dir_entry *find_dir_entry(struct index_state *istate,
-		const char *name, unsigned int namelen)
+static struct dir_entry *find_dir_entry_1(struct index_state *istate,
+		const char *name, unsigned int namelen, unsigned int hash)
 {
 	struct dir_entry key;
-	hashmap_entry_init(&key, memihash(name, namelen));
+	hashmap_entry_init(&key, hash);
 	key.namelen = namelen;
 	return hashmap_get(&istate->dir_hash, &key, name);
 }
 
+static struct dir_entry *find_dir_entry(struct index_state *istate,
+		const char *name, unsigned int namelen)
+{
+	return find_dir_entry_1(istate, name, namelen, memihash(name, namelen));
+}
+
 static struct dir_entry *hash_dir_entry(struct index_state *istate,
 		struct cache_entry *ce, int namelen)
 {
@@ -43,6 +49,7 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
 	 * in index_state.name_hash (as ordinary cache_entries).
 	 */
 	struct dir_entry *dir;
+	unsigned int hash;
 
 	/* get length of parent directory */
 	while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
@@ -52,11 +59,12 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
 	namelen--;
 
 	/* lookup existing entry for that directory */
-	dir = find_dir_entry(istate, ce->name, namelen);
+	hash = memihash(ce->name, namelen);
+	dir = find_dir_entry_1(istate, ce->name, namelen, hash);
 	if (!dir) {
 		/* not found, create it and add to hash table */
 		FLEX_ALLOC_MEM(dir, name, ce->name, namelen);
-		hashmap_entry_init(dir, memihash(ce->name, namelen));
+		hashmap_entry_init(dir, hash);
 		dir->namelen = namelen;
 		hashmap_add(&istate->dir_hash, dir);
 
-- 
2.11.1.windows.1
Previous: Junio C HamanoNext: Johannes Schindelin
Message 7 of 25 in “A series of performance enhancements in the memihash and name-cache area”
  1. 0/5 A series of performance enhancements in the memihash and name-cache areaJohannes Schindelin, Feb 14, 2017
  2. 5/5 name-hash: remember previous dir_entry during lazy_init_name_hashJohannes Schindelin, Feb 14, 2017
  3. 3/5 name-hash: precompute hash values during preload-indexJohannes Schindelin, Feb 14, 2017
  4. Junio C HamanoFeb 18, 2017
  5. Jeff HostetlerFeb 19, 2017
  6. Junio C HamanoFeb 19, 2017
  7. 1/5 name-hash: eliminate duplicate memihash callJohannes Schindelin, Feb 14, 2017
  8. 2/5 hashmap: allow memihash computation to be continuedJohannes Schindelin, Feb 14, 2017
  9. Junio C HamanoFeb 18, 2017
  10. Johannes SchindelinFeb 20, 2017
  11. Junio C HamanoFeb 20, 2017
  12. 4/5 name-hash: specify initial size for istate.dir_hash tableJohannes Schindelin, Feb 14, 2017
  13. Jeff KingFeb 14, 2017
  14. Jeff HostetlerFeb 15, 2017
  15. Jeff KingFeb 15, 2017
  16. Junio C HamanoFeb 18, 2017
  17. Jeff HostetlerFeb 19, 2017
  18. Junio C HamanoFeb 18, 2017
  19. Jeff KingFeb 18, 2017
  20. Junio C HamanoFeb 18, 2017
  21. Jeff HostetlerFeb 18, 2017
  22. Junio C HamanoFeb 19, 2017
  23. Junio C HamanoMar 2, 2017
  24. Jeff HostetlerMar 2, 2017
  25. Junio C HamanoMar 2, 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.