Skip to content

Commit 65ed868

Browse files
committed
Merge branch 'rs/discard-index-discard-array' into maint
* rs/discard-index-discard-array: read-cache: free cache in discard_index read-cache: add simple performance test
2 parents 7f05e4a + a0fc4db commit 65ed868

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
/test-mktemp
191191
/test-parse-options
192192
/test-path-utils
193+
/test-read-cache
193194
/test-regex
194195
/test-revision-walking
195196
/test-run-command

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
565565
TEST_PROGRAMS_NEED_X += test-mktemp
566566
TEST_PROGRAMS_NEED_X += test-parse-options
567567
TEST_PROGRAMS_NEED_X += test-path-utils
568+
TEST_PROGRAMS_NEED_X += test-read-cache
568569
TEST_PROGRAMS_NEED_X += test-regex
569570
TEST_PROGRAMS_NEED_X += test-revision-walking
570571
TEST_PROGRAMS_NEED_X += test-run-command

read-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,9 @@ int discard_index(struct index_state *istate)
15181518
free_name_hash(istate);
15191519
cache_tree_free(&(istate->cache_tree));
15201520
istate->initialized = 0;
1521-
1522-
/* no need to throw away allocated active_cache */
1521+
free(istate->cache);
1522+
istate->cache = NULL;
1523+
istate->cache_alloc = 0;
15231524
return 0;
15241525
}
15251526

t/perf/p0002-read-cache.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
test_description="Tests performance of reading the index"
4+
5+
. ./perf-lib.sh
6+
7+
test_perf_default_repo
8+
9+
count=1000
10+
test_perf "read_cache/discard_cache $count times" "
11+
test-read-cache $count
12+
"
13+
14+
test_done

test-read-cache.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "cache.h"
2+
3+
int main (int argc, char **argv)
4+
{
5+
int i, cnt = 1;
6+
if (argc == 2)
7+
cnt = strtol(argv[1], NULL, 0);
8+
for (i = 0; i < cnt; i++) {
9+
read_cache();
10+
discard_cache();
11+
}
12+
return 0;
13+
}

0 commit comments

Comments
 (0)