Merge branch 'rs/discard-index-discard-array'
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:30 +0000 (16:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:30 +0000 (16:02 -0700)
* rs/discard-index-discard-array:
read-cache: free cache in discard_index
read-cache: add simple performance test

.gitignore
Makefile
read-cache.c
t/perf/p0002-read-cache.sh [new file with mode: 0755]
test-read-cache.c [new file with mode: 0644]
index 1640c3ad005adbeecf4b90f92e5d3369c6490697..c0e00eb37bb370ce9deee72468fb419bc25cfd62 100644 (file)
 /test-mktemp
 /test-parse-options
 /test-path-utils
+/test-read-cache
 /test-regex
 /test-revision-walking
 /test-run-command
index 0d2d0cdd3e8b1304ee4348f6659c35ae2968aaeb..79f961ee4bf85b488aaa1c3f3fb9b8b28b414872 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -569,6 +569,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
+TEST_PROGRAMS_NEED_X += test-read-cache
 TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
index 5e30746886d477a0dc69853efd42283f2ac8c712..b297addb576dec45fa9b82ef4a0ffb350f9cfc6c 100644 (file)
@@ -1520,8 +1520,9 @@ int discard_index(struct index_state *istate)
        free_name_hash(istate);
        cache_tree_free(&(istate->cache_tree));
        istate->initialized = 0;
-
-       /* no need to throw away allocated active_cache */
+       free(istate->cache);
+       istate->cache = NULL;
+       istate->cache_alloc = 0;
        return 0;
 }
 
diff --git a/t/perf/p0002-read-cache.sh b/t/perf/p0002-read-cache.sh
new file mode 100755 (executable)
index 0000000..9180ae9
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+test_description="Tests performance of reading the index"
+
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+count=1000
+test_perf "read_cache/discard_cache $count times" "
+       test-read-cache $count
+"
+
+test_done
diff --git a/test-read-cache.c b/test-read-cache.c
new file mode 100644 (file)
index 0000000..b25bcf1
--- /dev/null
@@ -0,0 +1,13 @@
+#include "cache.h"
+
+int main (int argc, char **argv)
+{
+       int i, cnt = 1;
+       if (argc == 2)
+               cnt = strtol(argv[1], NULL, 0);
+       for (i = 0; i < cnt; i++) {
+               read_cache();
+               discard_cache();
+       }
+       return 0;
+}