commit - f73df793baa4ec89bcbfb0fddb9765c4187defc8
commit + 87c1ed2b2f3cd42280054f037b5a32c8fe6b7013
blob - 358389209a5812144cf90fd8c59a48aee2b1c150
blob + d1f67080cf2eb7c75f2329144cafe40603ae771f
--- lib/repository.c
+++ lib/repository.c
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;
}
}