@@ -34,19 +34,36 @@ static unsigned int hash_name(const char *name, int namelen)
3434 return hash ;
3535}
3636
37- static void set_index_entry (struct index_state * istate , int nr , struct cache_entry * ce )
37+ static void hash_index_entry (struct index_state * istate , struct cache_entry * ce )
3838{
3939 void * * pos ;
4040 unsigned int hash = hash_name (ce -> name , ce_namelen (ce ));
4141
42- istate -> cache [nr ] = ce ;
4342 pos = insert_hash (hash , ce , & istate -> name_hash );
4443 if (pos ) {
4544 ce -> next = * pos ;
4645 * pos = ce ;
4746 }
4847}
4948
49+ static void lazy_init_name_hash (struct index_state * istate )
50+ {
51+ int nr ;
52+
53+ if (istate -> name_hash_initialized )
54+ return ;
55+ for (nr = 0 ; nr < istate -> cache_nr ; nr ++ )
56+ hash_index_entry (istate , istate -> cache [nr ]);
57+ istate -> name_hash_initialized = 1 ;
58+ }
59+
60+ static void set_index_entry (struct index_state * istate , int nr , struct cache_entry * ce )
61+ {
62+ istate -> cache [nr ] = ce ;
63+ if (istate -> name_hash_initialized )
64+ hash_index_entry (istate , ce );
65+ }
66+
5067/*
5168 * We don't actually *remove* it, we can just mark it invalid so that
5269 * we won't find it in lookups.
@@ -75,7 +92,10 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
7592int index_name_exists (struct index_state * istate , const char * name , int namelen )
7693{
7794 unsigned int hash = hash_name (name , namelen );
78- struct cache_entry * ce = lookup_hash (hash , & istate -> name_hash );
95+ struct cache_entry * ce ;
96+
97+ lazy_init_name_hash (istate );
98+ ce = lookup_hash (hash , & istate -> name_hash );
7999
80100 while (ce ) {
81101 if (!(ce -> ce_flags & CE_UNHASHED )) {
0 commit comments