};
struct cache_entry {
+ struct hashmap_entry ent;
struct stat_data ce_stat_data;
unsigned int ce_mode;
unsigned int ce_flags;
unsigned int ce_namelen;
unsigned char sha1[20];
- struct cache_entry *next;
char name[FLEX_ARRAY]; /* more */
};
unsigned int state = dst->ce_flags & CE_STATE_MASK;
/* Don't copy hash chain and name */
- memcpy(dst, src, offsetof(struct cache_entry, next));
+ memcpy(&dst->ce_stat_data, &src->ce_stat_data,
+ offsetof(struct cache_entry, name) -
+ offsetof(struct cache_entry, ce_stat_data));
/* Restore the hash state */
dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state;
struct cache_time timestamp;
unsigned name_hash_initialized : 1,
initialized : 1;
- struct hash_table name_hash;
+ struct hashmap name_hash;
struct hashmap dir_hash;
};
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);
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]);
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;
}
return;
istate->name_hash_initialized = 0;
- free_hash(&istate->name_hash);
+ hashmap_free(&istate->name_hash, 0);
hashmap_free(&istate->dir_hash, 1);
}