commit a9bf0c2c43fb5545d5929f63896d06d00281cdd7 from: Stefan Sperling date: Fri Jun 22 08:35:09 2018 UTC no need to manually count elements of a set commit - f6be5c308af39aaf5dd86f08ed270f009ba12ed8 commit + a9bf0c2c43fb5545d5929f63896d06d00281cdd7 blob - 4eb219f9241f6980f82035f28f5128cab0f988c5 blob + fbcf7b53c0bdfe9bb34535846550f44b0c38fbb1 --- lib/got_lib_repository.h +++ 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; }; blob - 5900746421a52c01d51c4bbf365e42cce22e01f2 blob + a688bdaa5e2ba19b4cd1972d21e8d8d99c37f0e5 --- lib/repository.c +++ lib/repository.c @@ -154,8 +154,10 @@ cache_add(struct got_object_cache *cache, struct got_o { 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_o break; } free(ce); - cache->ncached--; } ce = calloc(1, sizeof(*ce)); @@ -190,8 +191,7 @@ cache_add(struct got_object_cache *cache, struct got_o free(ce); err = NULL; } - } else - cache->ncached++; + } return err; }