no need to manually count elements of a set
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
diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index 4eb219f..fbcf7b5 100644
--- a/lib/got_lib_repository.h
+++ b/lib/got_lib_repository.h
@@ -35,7 +35,6 @@ struct got_object_cache_entry {
struct got_object_cache {
enum got_object_chache_type type;
struct got_object_idset *set;
- int ncached;
int cache_hit;
int cache_miss;
};
diff --git a/lib/repository.c b/lib/repository.c
index 5900746..a688bda 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -154,8 +154,10 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
{
const struct got_error *err = NULL;
struct got_object_cache_entry *ce;
+ int nelem;
- if (cache->ncached >= GOT_OBJECT_CACHE_SIZE) {
+ nelem = got_object_idset_num_elements(cache->set);
+ if (nelem >= GOT_OBJECT_CACHE_SIZE) {
err = got_object_idset_remove_random((void **)&ce,
cache->set);
if (err)
@@ -169,7 +171,6 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
break;
}
free(ce);
- cache->ncached--;
}
ce = calloc(1, sizeof(*ce));
@@ -190,8 +191,7 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
free(ce);
err = NULL;
}
- } else
- cache->ncached++;
+ }
return err;
}