[babl] babl-cache: store tolerance as part of cache versioning



commit b55f7fb85fa8ffe6fab13e86a2e1790d7cd077d2
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Nov 15 14:22:48 2016 +0100

    babl-cache: store tolerance as part of cache versioning

 babl/babl-cache.c     |   15 ++++++++-------
 babl/babl-fish-path.c |   11 +++++------
 babl/babl-internal.h  |    1 +
 3 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/babl/babl-cache.c b/babl/babl-cache.c
index 37c9264..6a5b5e0 100644
--- a/babl/babl-cache.c
+++ b/babl/babl-cache.c
@@ -58,8 +58,7 @@ babl_fish_serialize (Babl *fish, char *dest, int n)
         {
           snprintf (d, n, "\t%s\n", 
             babl_get_name(fish->fish_path.conversion_list->items[i]  ));
-          n -= strlen (d);
-          d += strlen (d);
+          n -= strlen (d);d += strlen (d);
         }
       }
       break;
@@ -90,7 +89,7 @@ void babl_store_db (void)
   FILE *dbfile = fopen (fish_cache_path (), "w");
   if (!dbfile)
     return;
-  fprintf (dbfile, "#%s\n", BABL_GIT_VERSION);
+  fprintf (dbfile, "#%s BABL_TOLERANCE=%f\n", BABL_GIT_VERSION, _babl_legal_error ());
 
   /* sort the list of fishes by usage, making next run more efficient -
    * and the data easier to approach as source of profiling
@@ -190,11 +189,15 @@ void babl_init_db (void)
           break;
         case '#':
           /* if babl has changed in git .. drop whole cache */
-          if (strcmp ( &token[1], BABL_GIT_VERSION))
+          {
+            char buf[2048];
+            sprintf (buf, "#%s BABL_TOLERANCE=%f", BABL_GIT_VERSION, _babl_legal_error ());
+          if (strcmp ( token, buf))
           {
             free (contents);
             return;
           }
+          }
           break;
         case '\t':
           if (strchr (token, '='))
@@ -249,8 +252,7 @@ void babl_init_db (void)
           }
           else
           {
-            Babl *conv =
-                    (void*)babl_db_find(babl_conversion_db(), &token[1]);
+            Babl *conv = (void*)babl_db_find(babl_conversion_db(), &token[1]);
             if (!conv)
             {
               return;
@@ -279,4 +281,3 @@ void babl_init_db (void)
   if (contents)
     free (contents);
 }
-
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index e7973a2..c8ba588 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -94,12 +94,11 @@ _babl_fish_create_name (char       *buf,
                         const Babl *destination,
                         int         is_reference);
 
-static double legal_error (void);
 
 static int max_path_length (void);
 
 
-static double legal_error (void)
+double _babl_legal_error (void)
 {
   static double error = 0.0;
   const char   *env;
@@ -176,9 +175,9 @@ get_conversion_path (PathContext *pc,
           path_error *= (1.0 + babl_conversion_error ((BablConversion *) pc->current_path->items[i]));
         }
 
-      if (path_error - 1.0 <= legal_error ()) /* check this before the next;
-                                                 which does a more accurate
-                                                 measurement of the error */
+      if (path_error - 1.0 <= _babl_legal_error ())
+                /* check this before the more accurate measurement of error -
+                   to bail earlier */
         {
           FishPathInstrumentation fpi;
           memset (&fpi, 0, sizeof (fpi));
@@ -190,7 +189,7 @@ get_conversion_path (PathContext *pc,
 
           if ((path_cost < ref_cost) && /* do not use paths that took longer to compute than reference */
               (path_cost < pc->fish_path->fish_path.cost) &&
-              (path_error <= legal_error ()))
+              (path_error <= _babl_legal_error ()))
             {
               /* We have found the best path so far,
                * let's copy it into our new fish */
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index 614edab..cde8fc3 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -317,6 +317,7 @@ static inline double babl_parse_double (const char *str)
 }
 
 
+double _babl_legal_error (void);
 void babl_init_db (void);
 void babl_store_db (void);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]