[babl] fish cache: sort cached fish paths by descending usage



commit f328c493e92d3e120c5e46221ed2301babde228d
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 14 18:39:16 2016 +0100

    fish cache: sort cached fish paths by descending usage

 babl/babl.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/babl/babl.c b/babl/babl.c
index b7e45c9..2f63ac4 100644
--- a/babl/babl.c
+++ b/babl/babl.c
@@ -182,6 +182,14 @@ static const char *fish_cache_path (void)
   return "/tmp/babl.db"; // XXX: a $HOME/.cache/babl/fishes path might be better
 }
 
+static int compare_fish_pixels (const void *a, const void *b)
+{
+  const Babl **fa = a;
+  const Babl **fb = b;
+  return ((*fb)->fish.pixels - (*fa)->fish.pixels) +
+         ((*fb)->fish.processings - (*fa)->fish.processings);
+}
+
 static void babl_store_db (void)
 {
   BablDb *db = babl_fish_db ();
@@ -190,6 +198,13 @@ static void babl_store_db (void)
   if (!dbfile)
     return;
   fprintf (dbfile, "#babl 0 %i fishes\n", db->babl_list->count);
+
+  /* sort the list of fishes by usage, making next run more efficient -
+   * and the data easier to approach as source of profiling
+   */
+  qsort (db->babl_list->items, db->babl_list->count,
+         sizeof (Babl*), compare_fish_pixels);
+
   for (i = 0; i< db->babl_list->count; i++)
   {
     Babl *fish = db->babl_list->items[i];


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