From bda7f0728ac55e55d79ed0786c1b5ce2ef7e6117 Mon Sep 17 00:00:00 2001 From: Ben Peart Date: Fri, 26 May 2017 00:55:47 +0000 Subject: [PATCH] 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 Signed-off-by: Johannes Schindelin --- compat/win32/fscache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compat/win32/fscache.c b/compat/win32/fscache.c index 18871fa36f..1a4f2c2a93 100644 --- a/compat/win32/fscache.c +++ b/compat/win32/fscache.c @@ -257,10 +257,13 @@ static void fscache_clear(void) { struct hashmap_iter iter; struct fsentry *fse; - while ((fse = hashmap_iter_first(&map, &iter))) { + hashmap_disallow_rehash(&map, 1); + hashmap_iter_init(&map, &iter); + while ((fse = hashmap_iter_next(&iter))) { fscache_remove(fse); fsentry_release(fse); } + hashmap_disallow_rehash(&map, 0); } /*