@@ -23,23 +23,17 @@ static int dir_entry_cmp(const struct dir_entry *e1,
23
23
name ? name : e2 -> name , e1 -> namelen );
24
24
}
25
25
26
- static struct dir_entry * find_dir_entry__hash (struct index_state * istate ,
27
- const char * name , unsigned int namelen , unsigned int hash )
26
+ static struct dir_entry * find_dir_entry (struct index_state * istate ,
27
+ const char * name , unsigned int namelen )
28
28
{
29
29
struct dir_entry key ;
30
- hashmap_entry_init (& key , hash );
30
+ hashmap_entry_init (& key , memihash ( name , namelen ) );
31
31
key .namelen = namelen ;
32
32
return hashmap_get (& istate -> dir_hash , & key , name );
33
33
}
34
34
35
- static struct dir_entry * find_dir_entry (struct index_state * istate ,
36
- const char * name , unsigned int namelen )
37
- {
38
- return find_dir_entry__hash (istate , name , namelen , memihash (name ,namelen ));
39
- }
40
-
41
35
static struct dir_entry * hash_dir_entry (struct index_state * istate ,
42
- struct cache_entry * ce , int namelen , struct dir_entry * * p_previous_dir )
36
+ struct cache_entry * ce , int namelen )
43
37
{
44
38
/*
45
39
* Throw each directory component in the hash for quick lookup
@@ -49,18 +43,6 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
49
43
* in index_state.name_hash (as ordinary cache_entries).
50
44
*/
51
45
struct dir_entry * dir ;
52
- unsigned int hash ;
53
- int use_precomputed_dir_hash = 0 ;
54
-
55
- if (ce -> precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET ) {
56
- if (!(ce -> precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__DIR ))
57
- return NULL ; /* item does not have a parent directory */
58
- if (namelen == ce_namelen (ce )) {
59
- /* dir hash only valid for outer-most call (not recursive ones) */
60
- use_precomputed_dir_hash = 1 ;
61
- hash = ce -> precompute_hash_dir ;
62
- }
63
- }
64
46
65
47
/* get length of parent directory */
66
48
while (namelen > 0 && !is_dir_sep (ce -> name [namelen - 1 ]))
@@ -70,43 +52,24 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
70
52
namelen -- ;
71
53
72
54
/* lookup existing entry for that directory */
73
- if (p_previous_dir && * p_previous_dir
74
- && namelen == (* p_previous_dir )-> namelen
75
- && memcmp (ce -> name , (* p_previous_dir )-> name , namelen ) == 0 ) {
76
- /*
77
- * When our caller is sequentially iterating thru the index,
78
- * items in the same directory will be sequential, and therefore
79
- * refer to the same dir_entry.
80
- */
81
- dir = * p_previous_dir ;
82
- } else {
83
- if (!use_precomputed_dir_hash )
84
- hash = memihash (ce -> name , namelen );
85
- dir = find_dir_entry__hash (istate , ce -> name , namelen , hash );
86
- }
87
-
55
+ dir = find_dir_entry (istate , ce -> name , namelen );
88
56
if (!dir ) {
89
57
/* not found, create it and add to hash table */
90
58
FLEX_ALLOC_MEM (dir , name , ce -> name , namelen );
91
- hashmap_entry_init (dir , hash );
59
+ hashmap_entry_init (dir , memihash ( ce -> name , namelen ) );
92
60
dir -> namelen = namelen ;
93
61
hashmap_add (& istate -> dir_hash , dir );
94
62
95
63
/* recursively add missing parent directories */
96
- dir -> parent = hash_dir_entry (istate , ce , namelen , NULL );
64
+ dir -> parent = hash_dir_entry (istate , ce , namelen );
97
65
}
98
-
99
- if (p_previous_dir )
100
- * p_previous_dir = dir ;
101
-
102
66
return dir ;
103
67
}
104
68
105
- static void add_dir_entry (struct index_state * istate , struct cache_entry * ce ,
106
- struct dir_entry * * p_previous_dir )
69
+ static void add_dir_entry (struct index_state * istate , struct cache_entry * ce )
107
70
{
108
71
/* Add reference to the directory entry (and parents if 0). */
109
- struct dir_entry * dir = hash_dir_entry (istate , ce , ce_namelen (ce ), p_previous_dir );
72
+ struct dir_entry * dir = hash_dir_entry (istate , ce , ce_namelen (ce ));
110
73
while (dir && !(dir -> nr ++ ))
111
74
dir = dir -> parent ;
112
75
}
@@ -117,7 +80,7 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
117
80
* Release reference to the directory entry. If 0, remove and continue
118
81
* with parent directory.
119
82
*/
120
- struct dir_entry * dir = hash_dir_entry (istate , ce , ce_namelen (ce ), NULL );
83
+ struct dir_entry * dir = hash_dir_entry (istate , ce , ce_namelen (ce ));
121
84
while (dir && !(-- dir -> nr )) {
122
85
struct dir_entry * parent = dir -> parent ;
123
86
hashmap_remove (& istate -> dir_hash , dir , NULL );
@@ -126,25 +89,16 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
126
89
}
127
90
}
128
91
129
- static void hash_index_entry (struct index_state * istate , struct cache_entry * ce ,
130
- struct dir_entry * * p_previous_dir )
92
+ static void hash_index_entry (struct index_state * istate , struct cache_entry * ce )
131
93
{
132
- unsigned int h ;
133
-
134
94
if (ce -> ce_flags & CE_HASHED )
135
95
return ;
136
96
ce -> ce_flags |= CE_HASHED ;
137
-
138
- if (ce -> precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET )
139
- h = ce -> precompute_hash_name ;
140
- else
141
- h = memihash (ce -> name , ce_namelen (ce ));
142
-
143
- hashmap_entry_init (ce , h );
97
+ hashmap_entry_init (ce , memihash (ce -> name , ce_namelen (ce )));
144
98
hashmap_add (& istate -> name_hash , ce );
145
99
146
100
if (ignore_case )
147
- add_dir_entry (istate , ce , p_previous_dir );
101
+ add_dir_entry (istate , ce );
148
102
}
149
103
150
104
static int cache_entry_cmp (const struct cache_entry * ce1 ,
@@ -160,24 +114,22 @@ static int cache_entry_cmp(const struct cache_entry *ce1,
160
114
161
115
static void lazy_init_name_hash (struct index_state * istate )
162
116
{
163
- struct dir_entry * previous_dir = NULL ;
164
117
int nr ;
165
118
166
119
if (istate -> name_hash_initialized )
167
120
return ;
168
121
hashmap_init (& istate -> name_hash , (hashmap_cmp_fn ) cache_entry_cmp ,
169
122
istate -> cache_nr );
170
- hashmap_init (& istate -> dir_hash , (hashmap_cmp_fn ) dir_entry_cmp ,
171
- istate -> cache_nr );
123
+ hashmap_init (& istate -> dir_hash , (hashmap_cmp_fn ) dir_entry_cmp , 0 );
172
124
for (nr = 0 ; nr < istate -> cache_nr ; nr ++ )
173
- hash_index_entry (istate , istate -> cache [nr ], & previous_dir );
125
+ hash_index_entry (istate , istate -> cache [nr ]);
174
126
istate -> name_hash_initialized = 1 ;
175
127
}
176
128
177
129
void add_name_hash (struct index_state * istate , struct cache_entry * ce )
178
130
{
179
131
if (istate -> name_hash_initialized )
180
- hash_index_entry (istate , ce , NULL );
132
+ hash_index_entry (istate , ce );
181
133
}
182
134
183
135
void remove_name_hash (struct index_state * istate , struct cache_entry * ce )
@@ -284,45 +236,3 @@ void free_name_hash(struct index_state *istate)
284
236
hashmap_free (& istate -> name_hash , 0 );
285
237
hashmap_free (& istate -> dir_hash , 1 );
286
238
}
287
-
288
- /*
289
- * Precompute the hash values for this cache_entry
290
- * for use in the istate.name_hash and istate.dir_hash.
291
- *
292
- * If the item is in the root directory, just compute the
293
- * hash value (for istate.name_hash) on the full path.
294
- *
295
- * If the item is in a subdirectory, first compute the
296
- * hash value for the immediate parent directory (for
297
- * istate.dir_hash) and then the hash value for the full
298
- * path by continuing the computation.
299
- *
300
- * Note that these hashes will be used by
301
- * wt_status_collect_untracked() as it scans the worktree
302
- * and maps observed paths back to the index (optionally
303
- * ignoring case). Therefore, we probably only *NEED* to
304
- * precompute this for non-skip-worktree items (since
305
- * status should not observe skipped items), but because
306
- * lazy_init_name_hash() hashes everything, we force it
307
- * here.
308
- */
309
- void precompute_istate_hashes (struct cache_entry * ce )
310
- {
311
- int namelen = ce_namelen (ce );
312
-
313
- while (namelen > 0 && !is_dir_sep (ce -> name [namelen - 1 ]))
314
- namelen -- ;
315
-
316
- if (namelen <= 0 ) {
317
- ce -> precompute_hash_name = memihash (ce -> name , ce_namelen (ce ));
318
- ce -> precompute_hash_state = CE_PRECOMPUTE_HASH_STATE__SET ;
319
- } else {
320
- namelen -- ;
321
- ce -> precompute_hash_dir = memihash (ce -> name , namelen );
322
- ce -> precompute_hash_name = memihash_cont (
323
- ce -> precompute_hash_dir , & ce -> name [namelen ],
324
- ce_namelen (ce ) - namelen );
325
- ce -> precompute_hash_state =
326
- CE_PRECOMPUTE_HASH_STATE__SET | CE_PRECOMPUTE_HASH_STATE__DIR ;
327
- }
328
- }
0 commit comments