@@ -34,19 +34,36 @@ static unsigned int hash_name(const char *name, int namelen)
34
34
return hash ;
35
35
}
36
36
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 )
38
38
{
39
39
void * * pos ;
40
40
unsigned int hash = hash_name (ce -> name , ce_namelen (ce ));
41
41
42
- istate -> cache [nr ] = ce ;
43
42
pos = insert_hash (hash , ce , & istate -> name_hash );
44
43
if (pos ) {
45
44
ce -> next = * pos ;
46
45
* pos = ce ;
47
46
}
48
47
}
49
48
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
+
50
67
/*
51
68
* We don't actually *remove* it, we can just mark it invalid so that
52
69
* we won't find it in lookups.
@@ -75,7 +92,10 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
75
92
int index_name_exists (struct index_state * istate , const char * name , int namelen )
76
93
{
77
94
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 );
79
99
80
100
while (ce ) {
81
101
if (!(ce -> ce_flags & CE_UNHASHED )) {
0 commit comments