aboutsummaryrefslogtreecommitdiff
path: root/name-hash.c
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2013-11-14 20:21:58 +0100
committerJunio C Hamano <gitster@pobox.com>2013-11-18 13:04:24 -0800
commit8b013788a14b96b8d20b1f6bc76a42f9733aefad (patch)
tree6819f34323de1ad90c9517def56e35fc4ee32448 /name-hash.c
parent1c8cca190a1029d16450e61fbc4ce6f85a867f30 (diff)
downloadgit-8b013788a14b96b8d20b1f6bc76a42f9733aefad.tar.gz
git-8b013788a14b96b8d20b1f6bc76a42f9733aefad.tar.xz
name-hash.c: use new hash map implementation for cache entries
Note: the "ce->next = NULL;" in unpack-trees.c::do_add_entry can safely be removed, as ce->next (now ce->ent.next) is always properly initialized in name-hash.c::hash_index_entry. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'name-hash.c')
-rw-r--r--name-hash.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/name-hash.c b/name-hash.c
index effe96db0..488eccf2f 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -100,19 +100,11 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
{
- void **pos;
- unsigned int hash;
-
if (ce->ce_flags & CE_HASHED)
return;
ce->ce_flags |= CE_HASHED;
- ce->next = NULL;
- hash = memihash(ce->name, ce_namelen(ce));
- pos = insert_hash(hash, ce, &istate->name_hash);
- if (pos) {
- ce->next = *pos;
- *pos = ce;
- }
+ hashmap_entry_init(ce, memihash(ce->name, ce_namelen(ce)));
+ hashmap_add(&istate->name_hash, ce);
if (ignore_case && !(ce->ce_flags & CE_UNHASHED))
add_dir_entry(istate, ce);
@@ -124,8 +116,7 @@ static void lazy_init_name_hash(struct index_state *istate)
if (istate->name_hash_initialized)
return;
- if (istate->cache_nr)
- preallocate_hash(&istate->name_hash, istate->cache_nr);
+ hashmap_init(&istate->name_hash, NULL, istate->cache_nr);
hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0);
for (nr = 0; nr < istate->cache_nr; nr++)
hash_index_entry(istate, istate->cache[nr]);
@@ -221,18 +212,19 @@ struct cache_entry *index_dir_exists(struct index_state *istate, const char *nam
struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int icase)
{
- unsigned int hash = memihash(name, namelen);
struct cache_entry *ce;
+ struct hashmap_entry key;
lazy_init_name_hash(istate);
- ce = lookup_hash(hash, &istate->name_hash);
+ hashmap_entry_init(&key, memihash(name, namelen));
+ ce = hashmap_get(&istate->name_hash, &key, NULL);
while (ce) {
if (!(ce->ce_flags & CE_UNHASHED)) {
if (same_name(ce, name, namelen, icase))
return ce;
}
- ce = ce->next;
+ ce = hashmap_get_next(&istate->name_hash, ce);
}
return NULL;
}
@@ -250,6 +242,6 @@ void free_name_hash(struct index_state *istate)
return;
istate->name_hash_initialized = 0;
- free_hash(&istate->name_hash);
+ hashmap_free(&istate->name_hash, 0);
hashmap_free(&istate->dir_hash, 1);
}