Skip to content

Commit 08bcd77

Browse files
committed
Merge branch 'rs/discard-index-discard-array'
* rs/discard-index-discard-array: read-cache: free cache in discard_index read-cache: add simple performance test
2 parents 8f0c843 + a0fc4db commit 08bcd77

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
@@ -191,6 +191,7 @@
191191
/test-mktemp
192192
/test-parse-options
193193
/test-path-utils
194+
/test-read-cache
194195
/test-regex
195196
/test-revision-walking
196197
/test-run-command

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
569569
TEST_PROGRAMS_NEED_X += test-mktemp
570570
TEST_PROGRAMS_NEED_X += test-parse-options
571571
TEST_PROGRAMS_NEED_X += test-path-utils
572+
TEST_PROGRAMS_NEED_X += test-read-cache
572573
TEST_PROGRAMS_NEED_X += test-regex
573574
TEST_PROGRAMS_NEED_X += test-revision-walking
574575
TEST_PROGRAMS_NEED_X += test-run-command

read-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,9 @@ int discard_index(struct index_state *istate)
15201520
free_name_hash(istate);
15211521
cache_tree_free(&(istate->cache_tree));
15221522
istate->initialized = 0;
1523-
1524-
/* no need to throw away allocated active_cache */
1523+
free(istate->cache);
1524+
istate->cache = NULL;
1525+
istate->cache_alloc = 0;
15251526
return 0;
15261527
}
15271528

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)