commit 3333aec6eab7596a83037f6fc7abb9e0c8dee838 from: Stefan Sperling via: Thomas Adam date: Fri Oct 15 19:20:16 2021 UTC fix pack index cache element rotation; keep often used entries near the front commit - f1417e9f1c817d4e11dba207cf39ae12ffda2138 commit + 3333aec6eab7596a83037f6fc7abb9e0c8dee838 blob - bff284faf906f806e14b3b54a5308cd8dcb7f99b blob + a963c0de6158cfedb20185a2af26c5cb109e7cad --- lib/repository.c +++ lib/repository.c @@ -926,19 +926,13 @@ cache_packidx(struct got_repository *repo, struct got_ } } if (i == repo->pack_cache_size) { - err = got_packidx_close(repo->packidx_cache[i - 1]); + i = repo->pack_cache_size - 1; + err = got_packidx_close(repo->packidx_cache[i]); if (err) return err; } - /* - * Insert the new pack index at the front so it will - * be searched first in the future. - */ - memmove(&repo->packidx_cache[1], &repo->packidx_cache[0], - sizeof(repo->packidx_cache) - - sizeof(repo->packidx_cache[0])); - repo->packidx_cache[0] = packidx; + repo->packidx_cache[i] = packidx; return NULL; } @@ -982,10 +976,10 @@ got_repo_search_packidx(struct got_packidx **packidx, * searching a wrong pack index can be expensive. */ if (i > 0) { - struct got_packidx *p; - p = repo->packidx_cache[0]; + memmove(&repo->packidx_cache[1], + &repo->packidx_cache[0], + i * sizeof(repo->packidx_cache[0])); repo->packidx_cache[0] = *packidx; - repo->packidx_cache[i] = p; } return NULL; }