introduce struct got_object_cache
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index 6fc9d6a..db28762 100644
--- a/lib/got_lib_repository.h
+++ b/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*
diff --git a/lib/repository.c b/lib/repository.c
index 28df53b..9a2fb62 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -154,16 +154,16 @@ got_repo_cache_object(struct got_repository *repo, struct got_object_id *id,
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, struct got_object_id *id,
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, struct got_object_id *id,
}
} 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;
+ struct got_object_cache_entry *ce;
- ce = got_object_idset_get(repo->objcache, id);
+ 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 *path)
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);
}