commit 87c1ed2b2f3cd42280054f037b5a32c8fe6b7013 from: Stefan Sperling date: Tue Jan 07 21:50:38 2020 UTC don't bother swapping the first pack index cache pointer, and improve comment commit - f73df793baa4ec89bcbfb0fddb9765c4187defc8 commit + 87c1ed2b2f3cd42280054f037b5a32c8fe6b7013 blob - 358389209a5812144cf90fd8c59a48aee2b1c150 blob + d1f67080cf2eb7c75f2329144cafe40603ae771f --- lib/repository.c +++ lib/repository.c @@ -850,12 +850,17 @@ got_repo_search_packidx(struct got_packidx **packidx, break; *idx = got_packidx_get_object_idx(repo->packidx_cache[i], id); if (*idx != -1) { - struct got_packidx *p; - /* Move matched cache entry to the front. */ - p = repo->packidx_cache[0]; *packidx = repo->packidx_cache[i]; - repo->packidx_cache[0] = *packidx; - repo->packidx_cache[i] = p; + /* + * Move this cache entry to the front. Repeatedly + * searching a wrong pack index can be expensive. + */ + if (i > 0) { + struct got_packidx *p; + p = repo->packidx_cache[0]; + repo->packidx_cache[0] = *packidx; + repo->packidx_cache[i] = p; + } return NULL; } }