commit - f1417e9f1c817d4e11dba207cf39ae12ffda2138
commit + 3333aec6eab7596a83037f6fc7abb9e0c8dee838
blob - bff284faf906f806e14b3b54a5308cd8dcb7f99b
blob + a963c0de6158cfedb20185a2af26c5cb109e7cad
--- lib/repository.c
+++ lib/repository.c
}
}
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;
}
* 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;
}