From 8b013788a14b96b8d20b1f6bc76a42f9733aefad Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 14 Nov 2013 20:21:58 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- name-hash.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'name-hash.c') diff --git a/name-hash.c b/name-hash.c index effe96db0b..488eccf2f9 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); } -- cgit v1.2.3