Skip to content

Commit a0fc4db

Browse files
René Scharfegitster
authored andcommitted
read-cache: free cache in discard_index
discard_cache doesn't have to free the array of cache entries, because the next call of read_cache can simply reuse it, as they all operate on the global variable the_index. discard_index on the other hand does have to free it, because it can be used e.g. with index_state variables on the stack, in which case a missing free would cause an unrecoverable leak. This patch releases the memory and removes a comment that was relevant for discard_cache but has become outdated. Since discard_cache is just a wrapper around discard_index nowadays, we lose the optimization that avoids reallocation of that array within loops of read_cache and discard_cache. That doesn't cause a performance regression for me, however (HEAD = this patch, HEAD^ = master + p0002): Test // HEAD^ HEAD ---------------\\----------------------------------------------------- 0002.1: read_ca// 1000 times 0.62(0.58+0.04) 0.61(0.58+0.02) -1.6% Suggested-by: Felipe Contreras <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ecb5ff commit a0fc4db

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

0 commit comments

Comments
 (0)