Skip to content

Commit bda7f07

Browse files
Ben Peartdscho
authored andcommitted
fixup! Win32: add a cache below mingw's lstat and dirent implementations
The fscache_clear() function used to be O(n^2). But we can easily make it O(n) instead. Update fscache_clear to be O(n) instead of O(n^2) by using inter_next instead of starting from the begining each time with iter_first. While at it, also disallow rehashing while removing the entries. This speeds up a simple `git commit -m foo` when fscache is enabled (because fscache_clear() is called implicitly by preload_index()). Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 51efe4d commit bda7f07

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compat/win32/fscache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,13 @@ static void fscache_clear(void)
257257
{
258258
struct hashmap_iter iter;
259259
struct fsentry *fse;
260-
while ((fse = hashmap_iter_first(&map, &iter))) {
260+
hashmap_disallow_rehash(&map, 1);
261+
hashmap_iter_init(&map, &iter);
262+
while ((fse = hashmap_iter_next(&iter))) {
261263
fscache_remove(fse);
262264
fsentry_release(fse);
263265
}
266+
hashmap_disallow_rehash(&map, 0);
264267
}
265268

266269
/*

0 commit comments

Comments
 (0)