diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2018-04-23 21:56:32 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2018-04-23 22:00:13 +0200 |
commit | 359a4078a8adad86bf028cd4d48210379eea0f7b (patch) | |
tree | 142b022d21362b4b57fa9c6c2a7e7d1abbbf5cef | |
parent | 047d387da9d4dfe8a4e5af6b47859e7e8c15be6f (diff) | |
download | ccache-359a4078a8adad86bf028cd4d48210379eea0f7b.tar.gz |
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 <float.h> which I think is superfluous.
-rw-r--r-- | src/ccache.h | 2 | ||||
-rw-r--r-- | src/cleanup.c | 19 |
2 files changed, 10 insertions, 11 deletions
diff --git a/src/ccache.h b/src/ccache.h index a4fd28ab..973d42dd 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 dbb65784..969b8d2b 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -17,7 +17,6 @@ #include "ccache.h" -#include <float.h> #include <math.h> 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); |