]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use double when calculating cache thresholds
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 23 Apr 2018 19:56:32 +0000 (21:56 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 23 Apr 2018 20:00:13 +0000 (22:00 +0200)
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.

src/ccache.h
src/cleanup.c

index a4fd28ab9bf56e49f71349bb6652c074dd839f13..973d42dd3c7af9cda1fb245117f9533430e738d2 100644 (file)
@@ -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);
 
index dbb657843c3f951b90e073eeed185a5c41138ee9..969b8d2bc80ba147d575be57291a15f46f67cc70 100644 (file)
@@ -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);