]> git.ipfire.org Git - thirdparty/git.git/commit - read-cache.c
read-cache: free cache in discard_index
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Sun, 9 Jun 2013 17:39:18 +0000 (19:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jun 2013 00:03:01 +0000 (17:03 -0700)
commita0fc4db01dfa69d836dc6f24218974a674ec29ac
tree59d85babf3b4aea2ccc0f9f9816bf1ef4505f23f
parent1ecb5ff141f6e54727c746446b52af51016e662c
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 <felipe.contreras@gmail.com>
Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c