[cairo] [PATCH] perf: Refactor some common macros to cairo-perf.h

Bryce W. Harrington b.harrington at samsung.com
Thu Apr 17 13:33:33 PDT 2014


These macros are standard in src's cairoint.h and test's cairo-test.h
internal header files, so for consistency do the same thing with perf's
cairo-perf.h.

Signed-off-by: Bryce Harrington <b.harrington at samsung.com>
---
 perf/cairo-perf-chart.c            |    2 --
 perf/cairo-perf-compare-backends.c |    1 -
 perf/cairo-perf-trace.c            |    5 ++---
 perf/cairo-perf.h                  |   12 ++++++++++++
 perf/micro/cairo-perf-cover.c      |    5 ++---
 perf/micro/dragon.c                |    8 --------
 perf/micro/zrusin.c                |    4 +---
 7 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/perf/cairo-perf-chart.c b/perf/cairo-perf-chart.c
index 1faa964..738fe5c 100644
--- a/perf/cairo-perf-chart.c
+++ b/perf/cairo-perf-chart.c
@@ -57,8 +57,6 @@ struct color {
 #define FONT_SIZE 12
 #define PAD (4)
 
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-
 static double
 to_factor (double x)
 {
diff --git a/perf/cairo-perf-compare-backends.c b/perf/cairo-perf-compare-backends.c
index 2cbb24c..ff7359e 100644
--- a/perf/cairo-perf-compare-backends.c
+++ b/perf/cairo-perf-compare-backends.c
@@ -149,7 +149,6 @@ test_diff_print (test_diff_t		     *diff,
     printf("\n");
 }
 
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
 static void
 cairo_perf_reports_compare (cairo_perf_report_t 	*reports,
 			    int 			 num_reports,
diff --git a/perf/cairo-perf-trace.c b/perf/cairo-perf-trace.c
index f27f8e4..02e0e29 100644
--- a/perf/cairo-perf-trace.c
+++ b/perf/cairo-perf-trace.c
@@ -199,7 +199,6 @@ scache_equal (const void *A,
     return a->entry.hash == b->entry.hash;
 }
 
-#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
 static void
 scache_mark_active (cairo_surface_t *surface)
 {
@@ -210,7 +209,7 @@ scache_mark_active (cairo_surface_t *surface)
 	return;
 
     t0 = cairo_surface_reference (surface);
-    for (n = 0; n < ARRAY_SIZE (surface_holdovers); n++) {
+    for (n = 0; n < ARRAY_LENGTH (surface_holdovers); n++) {
 	if (surface_holdovers[n] == surface) {
 	    surface_holdovers[n] = t0;
 	    t0 = surface;
@@ -232,7 +231,7 @@ scache_clear (void)
     if (surface_cache == NULL)
 	return;
 
-    for (n = 0; n < ARRAY_SIZE (surface_holdovers); n++) {
+    for (n = 0; n < ARRAY_LENGTH (surface_holdovers); n++) {
 	cairo_surface_destroy (surface_holdovers[n]);
 	surface_holdovers[n] = NULL;
     }
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 4e898ac..b32b0e0 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -195,6 +195,18 @@ test_report_cmp_name (const void *a,
 
 #define CAIRO_PERF_DECL(func) CAIRO_PERF_RUN_DECL(func); CAIRO_PERF_ENABLED_DECL(func)
 
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef ARRAY_LENGTH
+#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
+#endif
+
 CAIRO_PERF_DECL (fill);
 CAIRO_PERF_DECL (paint);
 CAIRO_PERF_DECL (paint_with_alpha);
diff --git a/perf/micro/cairo-perf-cover.c b/perf/micro/cairo-perf-cover.c
index 151a2e6..c249902 100644
--- a/perf/micro/cairo-perf-cover.c
+++ b/perf/micro/cairo-perf-cover.c
@@ -290,7 +290,6 @@ set_source_radial_rgba (cairo_t *cr,
 }
 
 typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
-#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
 
 void
 cairo_perf_cover_sources_and_operators (cairo_perf_t		*perf,
@@ -325,10 +324,10 @@ cairo_perf_cover_sources_and_operators (cairo_perf_t		*perf,
 	{ CAIRO_OPERATOR_SOURCE, "source" }
     };
 
-    for (i = 0; i < ARRAY_SIZE (sources); i++) {
+    for (i = 0; i < ARRAY_LENGTH (sources); i++) {
 	(sources[i].set_source) (perf->cr, perf->size, perf->size);
 
-	for (j = 0; j < ARRAY_SIZE (operators); j++) {
+	for (j = 0; j < ARRAY_LENGTH (operators); j++) {
 	    cairo_set_operator (perf->cr, operators[j].op);
 
 	    xasprintf (&expanded_name, "%s_%s_%s",
diff --git a/perf/micro/dragon.c b/perf/micro/dragon.c
index e215eac..aa5daf5 100644
--- a/perf/micro/dragon.c
+++ b/perf/micro/dragon.c
@@ -28,14 +28,6 @@
 
 #include "cairo-perf.h"
 
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#ifndef MAX
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
 static inline int
 next_pot (int v)
 {
diff --git a/perf/micro/zrusin.c b/perf/micro/zrusin.c
index 7d8b004..3dee74d 100644
--- a/perf/micro/zrusin.c
+++ b/perf/micro/zrusin.c
@@ -33,14 +33,12 @@ typedef struct {
 
 #include "zrusin-another.h"
 
-#define ARRAY_SIZE(arr) sizeof(arr)/sizeof(arr[0])
-
 static void
 zrusin_another_path (cairo_t *cr)
 {
     unsigned int i;
 
-    for (i=0; i < ARRAY_SIZE (zrusin_another); i++)
+    for (i=0; i < ARRAY_LENGTH (zrusin_another); i++)
 	cairo_line_to (cr, zrusin_another[i].x, zrusin_another[i].y);
 }
 
-- 
1.7.9.5


More information about the cairo mailing list