[babl] Only initialize test buffers once



commit 225d70ba0d3a191be46bf671afc351f1fd8b4f27
Author: �yvind Kolås <pippin gimp org>
Date:   Sun Nov 29 15:42:05 2009 +0000

    Only initialize test buffers once
    
    Also made the test buffer static inline for individual conversions like
    it already was for fish paths.
    
    Note, this relies on none of the tested conversions by accident
    being buggy enough to modify their source data, adding a sanity
    function that compares the buffers with the correct values could
    perhaps be useful.

 babl/babl-conversion.c |   14 +++++++++-----
 babl/babl-fish-path.c  |    5 +++++
 2 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c
index e08b2e6..422e2dd 100644
--- a/babl/babl-conversion.c
+++ b/babl/babl-conversion.c
@@ -420,18 +420,23 @@ babl_conversion_process (Babl *babl,
 
 #define test_pixels    512
 
+
 static double *
 test_create (void)
 {
-  double *test;
-  int     i;
+  static double test[sizeof (double) * test_pixels * 4];
+  int           i;
+  static int done = 0;
 
-  srandom (20050728);
+  if (done)
+    return test;
 
-  test = babl_malloc (sizeof (double) * test_pixels * 4);
+  srandom (20050728);
 
   for (i = 0; i < test_pixels * 4; i++)
     test [i] = (double) random () / RAND_MAX;
+
+  done = 1;
   return test;
 }
 
@@ -548,7 +553,6 @@ babl_conversion_error (BablConversion *conversion)
   babl_free (destination_rgba_double);
   babl_free (ref_destination);
   babl_free (ref_destination_rgba_double);
-  babl_free (test);
 
   conversion->error = error;
   conversion->cost  = babl_process_cost (ticks_start, ticks_end);
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index d0932f3..2622cb3 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -465,6 +465,10 @@ test_create (void)
 {
   static double test[sizeof (double) * NUM_TEST_PIXELS * 4];
   int           i, j;
+  static int    done = 0;
+
+  if (done)
+    return test;
 
   /* There is no need to generate the test
    * more times ... */
@@ -483,6 +487,7 @@ test_create (void)
   for (j = 0; j < 16 * 4; i++, j++)
     test [i] = 1.0 + (double) random () / RAND_MAX;
 
+  done = 1;
   return test;
 }
 



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