From: Joel Rosdahl Date: Mon, 23 Apr 2018 19:56:32 +0000 (+0200) Subject: Use double when calculating cache thresholds X-Git-Tag: v3.4.3~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=359a4078a8adad86bf028cd4d48210379eea0f7b;p=thirdparty%2Fccache.git Use double when calculating cache thresholds We could at least in theory have large enough caches that float’s precision won’t be enough. Also removed include of which I think is superfluous. --- diff --git a/src/ccache.h b/src/ccache.h index a4fd28ab9..973d42dd3 100644 --- a/src/ccache.h +++ b/src/ccache.h @@ -233,7 +233,7 @@ void exitfn_call(void); // ---------------------------------------------------------------------------- // cleanup.c -void clean_up_dir(struct conf *conf, const char *dir, float limit_multiple); +void clean_up_dir(struct conf *conf, const char *dir, double limit_multiple); void clean_up_all(struct conf *conf); void wipe_all(struct conf *conf); diff --git a/src/cleanup.c b/src/cleanup.c index dbb657843..969b8d2bc 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -17,7 +17,6 @@ #include "ccache.h" -#include #include static struct files { @@ -158,15 +157,15 @@ sort_and_clean(void) // Clean up one cache subdirectory. void -clean_up_dir(struct conf *conf, const char *dir, float limit_multiple) +clean_up_dir(struct conf *conf, const char *dir, double limit_multiple) { cc_log("Cleaning up cache directory %s", dir); // When "max files" or "max cache size" is reached, one of the 16 cache // subdirectories is cleaned up. When doing so, files are deleted (in LRU // order) until the levels are below limit_multiple. - cache_size_threshold = roundf(conf->max_size * limit_multiple / 16); - files_in_cache_threshold = roundf(conf->max_files * limit_multiple / 16); + cache_size_threshold = round(conf->max_size * limit_multiple / 16); + files_in_cache_threshold = round(conf->max_files * limit_multiple / 16); num_files = 0; cache_size = 0; @@ -176,13 +175,13 @@ clean_up_dir(struct conf *conf, const char *dir, float limit_multiple) traverse(dir, traverse_fn); // Clean the cache. - cc_log("Before cleanup: %lu KiB, %.0f files", - (unsigned long)cache_size / 1024, - (float)files_in_cache); + cc_log("Before cleanup: %.0f KiB, %.0f files", + (double)cache_size / 1024, + (double)files_in_cache); bool cleaned = sort_and_clean(); - cc_log("After cleanup: %lu KiB, %.0f files", - (unsigned long)cache_size / 1024, - (float)files_in_cache); + cc_log("After cleanup: %.0f KiB, %.0f files", + (double)cache_size / 1024, + (double)files_in_cache); if (cleaned) { cc_log("Cleaned up cache directory %s", dir);