commit 54f20211c589e3522ed62f05814143d5450a49a7 from: Stefan Sperling date: Fri Jun 22 08:00:23 2018 UTC introduce struct got_object_cache commit - ebfa99d6a25310757c9b80ab139cac537ac26dfc commit + 54f20211c589e3522ed62f05814143d5450a49a7 blob - 6fc9d6a8011f70f7bb9c65e2ce6184b288b29f98 blob + db2876225fd8367257df47e56a7a1744ac8632b5 --- lib/got_lib_repository.h +++ lib/got_lib_repository.h @@ -19,11 +19,18 @@ #define GOT_OBJECT_CACHE_SIZE 8192 -struct got_objcache_entry { +struct got_object_cache_entry { struct got_object_id id; struct got_object *obj; }; +struct got_object_cache { + struct got_object_idset *set; + int ncached; + int cache_hit; + int cache_miss; +}; + struct got_repository { char *path; char *path_git_dir; @@ -34,10 +41,7 @@ struct got_repository { /* Open file handles for pack files. */ struct got_pack packs[GOT_PACK_CACHE_SIZE]; - struct got_object_idset *objcache; - int ncached; - int cache_hit; - int cache_miss; + struct got_object_cache objcache; }; const struct got_error* blob - 28df53bafa09c4b36087e5de8cae9d29844edf5c blob + 9a2fb62cf1d7a941a30ddef9c72e45717d09a5e6 --- lib/repository.c +++ lib/repository.c @@ -154,16 +154,16 @@ got_repo_cache_object(struct got_repository *repo, str struct got_object *obj) { const struct got_error *err = NULL; - struct got_objcache_entry *ce; + struct got_object_cache_entry *ce; - if (repo->ncached >= GOT_OBJECT_CACHE_SIZE) { + if (repo->objcache.ncached >= GOT_OBJECT_CACHE_SIZE) { err = got_object_idset_remove_random((void **)&ce, - repo->objcache); + repo->objcache.set); if (err) return err; got_object_close(ce->obj); free(ce); - repo->ncached--; + repo->objcache.ncached--; } ce = calloc(1, sizeof(*ce)); @@ -171,7 +171,7 @@ got_repo_cache_object(struct got_repository *repo, str return got_error_from_errno(); memcpy(&ce->id, id, sizeof(ce->id)); ce->obj = obj; - err = got_object_idset_add(NULL, repo->objcache, id, ce); + err = got_object_idset_add(NULL, repo->objcache.set, id, ce); if (err) { if (err->code == GOT_ERR_OBJ_EXISTS) { free(ce); @@ -179,7 +179,7 @@ got_repo_cache_object(struct got_repository *repo, str } } else { obj->refcnt++; - repo->ncached++; + repo->objcache.ncached++; } return err; @@ -189,14 +189,14 @@ struct got_object * got_repo_get_cached_object(struct got_repository *repo, struct got_object_id *id) { - struct got_objcache_entry *ce; - - ce = got_object_idset_get(repo->objcache, id); + struct got_object_cache_entry *ce; + + ce = got_object_idset_get(repo->objcache.set, id); if (ce) { - repo->cache_hit++; + repo->objcache.cache_hit++; return ce->obj; } - repo->cache_miss++; + repo->objcache.cache_miss++; return NULL; } @@ -220,8 +220,8 @@ got_repo_open(struct got_repository **ret, const char goto done; } - repo->objcache = got_object_idset_alloc(); - if (repo->objcache == NULL) { + repo->objcache.set = got_object_idset_alloc(); + if (repo->objcache.set == NULL) { err = got_error_from_errno(); goto done; } @@ -299,7 +299,7 @@ got_repo_close(struct got_repository *repo) free(repo->path); free(repo->path_git_dir); - if (repo->objcache) - got_object_idset_free(repo->objcache); + if (repo->objcache.set) + got_object_idset_free(repo->objcache.set); free(repo); }