4 * Hashing names in the index state
6 * Copyright (C) 2008 Linus Torvalds
8 #define NO_THE_INDEX_COMPATIBILITY_MACROS
11 static unsigned int hash_name(const char *name
, int namelen
)
13 unsigned int hash
= 0x123;
16 unsigned char c
= *name
++;
22 static void hash_index_entry(struct index_state
*istate
, struct cache_entry
*ce
)
27 if (ce
->ce_flags
& CE_HASHED
)
29 ce
->ce_flags
|= CE_HASHED
;
31 hash
= hash_name(ce
->name
, ce_namelen(ce
));
32 pos
= insert_hash(hash
, ce
, &istate
->name_hash
);
39 static void lazy_init_name_hash(struct index_state
*istate
)
43 if (istate
->name_hash_initialized
)
45 for (nr
= 0; nr
< istate
->cache_nr
; nr
++)
46 hash_index_entry(istate
, istate
->cache
[nr
]);
47 istate
->name_hash_initialized
= 1;
50 void add_name_hash(struct index_state
*istate
, struct cache_entry
*ce
)
52 ce
->ce_flags
&= ~CE_UNHASHED
;
53 if (istate
->name_hash_initialized
)
54 hash_index_entry(istate
, ce
);
57 int index_name_exists(struct index_state
*istate
, const char *name
, int namelen
)
59 unsigned int hash
= hash_name(name
, namelen
);
60 struct cache_entry
*ce
;
62 lazy_init_name_hash(istate
);
63 ce
= lookup_hash(hash
, &istate
->name_hash
);
66 if (!(ce
->ce_flags
& CE_UNHASHED
)) {
67 if (!cache_name_compare(name
, namelen
, ce
->name
, ce
->ce_flags
))