[cairo-commit] 2 commits - src/cairo-arc.c src/cairo-atsui-font.c src/cairo-bentley-ottmann.c src/cairo-cff-subset.c src/cairo-hash.c src/cairoint.h src/cairo-pattern.c src/cairo-polygon.c src/cairo-spline.c src/cairo-surface.c src/cairo-svg-surface.c src/cairo-traps.c src/cairo-truetype-subset.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Mar 20 15:59:17 PDT 2007


 src/cairo-arc.c             |    2 +-
 src/cairo-atsui-font.c      |    6 ++----
 src/cairo-bentley-ottmann.c |    2 +-
 src/cairo-cff-subset.c      |    8 +++-----
 src/cairo-hash.c            |    2 +-
 src/cairo-pattern.c         |    2 +-
 src/cairo-polygon.c         |    2 +-
 src/cairo-spline.c          |    2 +-
 src/cairo-surface.c         |   13 +++++++++----
 src/cairo-svg-surface.c     |    2 +-
 src/cairo-traps.c           |    2 +-
 src/cairo-truetype-subset.c |    8 +++-----
 src/cairoint.h              |    3 +++
 13 files changed, 28 insertions(+), 26 deletions(-)

New commits:
diff-tree ad51ee5aa0d1fc03c4ebe7f0454949995420a710 (from 1de12714a9623e66309279eb9edaf6053fd92c56)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Mar 20 18:59:19 2007 -0400

    Define and use ARRAY_LEN

diff --git a/src/cairo-arc.c b/src/cairo-arc.c
index 2bf6c89..7b2789d 100644
--- a/src/cairo-arc.c
+++ b/src/cairo-arc.c
@@ -85,7 +85,7 @@ _arc_max_angle_for_tolerance_normalized 
 	{ M_PI / 10.0,  1.73863223499021216974e-08 },
 	{ M_PI / 11.0,  9.81410988043554039085e-09 },
     };
-    int table_size = (sizeof (table) / sizeof (table[0]));
+    int table_size = ARRAY_LEN (table);
 
     for (i = 0; i < table_size; i++)
 	if (table[i].error < tolerance)
diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index a26e76f..7873808 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -117,8 +117,7 @@ _cairo_atsui_font_face_scaled_font_creat
     ATSUStyle style;
 
     err = ATSUCreateStyle (&style);
-    err = ATSUSetAttributes(style,
-                            sizeof(styleTags) / sizeof(styleTags[0]),
+    err = ATSUSetAttributes(style, ARRAY_LEN (styleTags),
                             styleTags, styleSizes, styleValues);
 
     return _cairo_atsui_font_create_scaled (&font_face->base, font_face->font_id, style,
@@ -374,8 +373,7 @@ _cairo_atsui_font_create_toy(cairo_toy_f
 	ByteCount styleSizes[] =
 	    { sizeof(Boolean), sizeof(Boolean), sizeof(ATSUFontID) };
 
-	err = ATSUSetAttributes(style,
-				sizeof(styleTags) / sizeof(styleTags[0]),
+	err = ATSUSetAttributes(style, ARRAY_LEN (styleTags),
 				styleTags, styleSizes, styleValues);
     }
 
diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index 928b6cd..873bfd6 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -1771,7 +1771,7 @@ main (void)
     unsigned int i, num_random;
     test_t *test;
 
-    for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
+    for (i = 0; i < ARRAY_LEN (tests); i++) {
 	test = &tests[i];
 	run_test (test->name, test->edges, test->num_edges);
     }
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index b354989..1cdedee 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -58,8 +58,6 @@
 
 #define NUM_STD_STRINGS 391
 
-#define ARRAY_LENGTH(a) ( (sizeof (a)) / (sizeof ((a)[0])) )
-
 typedef struct _cff_header {
     uint8_t major;
     uint8_t minor;
@@ -897,7 +895,7 @@ cairo_cff_font_read_font (cairo_cff_font
     cairo_int_status_t status;
     unsigned int i;
 
-    for (i = 0; i < ARRAY_LENGTH (font_read_funcs); i++) {
+    for (i = 0; i < ARRAY_LEN (font_read_funcs); i++) {
         status = font_read_funcs[i] (font);
         if (status)
             return status;
@@ -957,7 +955,7 @@ cairo_cff_font_subset_dict_strings (cair
     cairo_status_t status;
     unsigned int i;
 
-    for (i = 0; i < ARRAY_LENGTH (dict_strings); i++) {
+    for (i = 0; i < ARRAY_LEN (dict_strings); i++) {
         status = cairo_cff_font_subset_dict_string (font, dict, dict_strings[i]);
         if (status)
             return status;
@@ -1318,7 +1316,7 @@ cairo_cff_font_write_subset (cairo_cff_f
     cairo_int_status_t status;
     unsigned int i;
 
-    for (i = 0; i < ARRAY_LENGTH (font_write_funcs); i++) {
+    for (i = 0; i < ARRAY_LEN (font_write_funcs); i++) {
         status = font_write_funcs[i] (font);
         if (status)
             return status;
diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index 948cd23..31de811 100644
--- a/src/cairo-hash.c
+++ b/src/cairo-hash.c
@@ -115,7 +115,7 @@ static const cairo_hash_table_arrangemen
     { 268435456,	590559793,	590559791	}
 };
 
-#define NUM_HASH_TABLE_ARRANGEMENTS ((int)(sizeof(hash_table_arrangements)/sizeof(hash_table_arrangements[0])))
+#define NUM_HASH_TABLE_ARRANGEMENTS ARRAY_LEN (hash_table_arrangements)
 
 struct _cairo_hash_table {
     cairo_hash_keys_equal_func_t keys_equal;
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 6ebe0ca..beb95e8 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -720,7 +720,7 @@ _cairo_pattern_gradient_grow (cairo_grad
 {
     pixman_gradient_stop_t *new_stops;
     int old_size = pattern->stops_size;
-    int embedded_size = sizeof (pattern->stops_embedded) / sizeof (pattern->stops_embedded[0]);
+    int embedded_size = ARRAY_LEN (pattern->stops_embedded);
     int new_size = 2 * MAX (old_size, 4);
 
     /* we have a local buffer at pattern->stops_embedded.  try to fulfill the request
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 52c72b7..f36bc71 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -72,7 +72,7 @@ _cairo_polygon_grow (cairo_polygon_t *po
 {
     cairo_edge_t *new_edges;
     int old_size = polygon->edges_size;
-    int embedded_size = sizeof (polygon->edges_embedded) / sizeof (polygon->edges_embedded[0]);
+    int embedded_size = ARRAY_LEN (polygon->edges_embedded);
     int new_size = 2 * MAX (old_size, 16);
 
     /* we have a local buffer at polygon->edges_embedded.  try to fulfill the request
diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index 3624bfc..42151aa 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -104,7 +104,7 @@ _cairo_spline_grow (cairo_spline_t *spli
 {
     cairo_point_t *new_points;
     int old_size = spline->points_size;
-    int embedded_size = sizeof (spline->points_embedded) / sizeof (spline->points_embedded[0]);
+    int embedded_size = ARRAY_LEN (spline->points_embedded);
     int new_size = 2 * MAX (old_size, 16);
 
     /* we have a local buffer at spline->points_embedded.  try to fulfill the request
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index c28b895..aa4f3b8 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1181,7 +1181,7 @@ _cairo_surface_fill_region (cairo_surfac
 	return CAIRO_STATUS_SUCCESS;
 
     rects = stack_rects;
-    if (num_rects > (int) (sizeof (stack_rects) / sizeof (stack_rects[0]))) {
+    if (num_rects > ARRAY_LEN (stack_rects)) {
 	rects = malloc (sizeof (cairo_rectangle_int16_t) * num_rects);
 	if (!rects)
 	    return CAIRO_STATUS_NO_MEMORY;
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 5cb9ce0..0da1557 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -59,7 +59,7 @@ static const cairo_svg_version_t _cairo_
     CAIRO_SVG_VERSION_1_2
 };
 
-#define CAIRO_SVG_VERSION_LAST ((int)(sizeof (_cairo_svg_versions) / sizeof (_cairo_svg_versions[0])))
+#define CAIRO_SVG_VERSION_LAST ARRAY_LEN (_cairo_svg_versions)
 
 static cairo_bool_t
 _cairo_svg_version_has_page_set_support (cairo_svg_version_t version)
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index dd5837b..65075c2 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -187,7 +187,7 @@ _cairo_traps_grow (cairo_traps_t *traps)
 {
     cairo_trapezoid_t *new_traps;
     int old_size = traps->traps_size;
-    int embedded_size = sizeof (traps->traps_embedded) / sizeof (traps->traps_embedded[0]);
+    int embedded_size = ARRAY_LEN (traps->traps_embedded);
     int new_size = 2 * MAX (old_size, 16);
 
     /* we have a local buffer at traps->traps_embedded.  try to fulfill the request
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 7e77bb8..a99aed7 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -75,8 +75,6 @@ typedef struct _cairo_truetype_font {
 static int
 cairo_truetype_font_use_glyph (cairo_truetype_font_t *font, int glyph);
 
-#define ARRAY_LENGTH(a) ( (sizeof (a)) / (sizeof ((a)[0])) )
-
 #define SFNT_VERSION			0x00010000
 #define SFNT_STRING_MAX_LENGTH  65535
 
@@ -705,7 +703,7 @@ cairo_truetype_font_write_offset_table (
     unsigned short search_range, entry_selector, range_shift;
     int num_tables;
 
-    num_tables = ARRAY_LENGTH (truetype_tables);
+    num_tables = ARRAY_LEN (truetype_tables);
     search_range = 1;
     entry_selector = 0;
     while (search_range * 2 <= num_tables) {
@@ -724,7 +722,7 @@ cairo_truetype_font_write_offset_table (
     /* Allocate space for the table directory. Each directory entry
      * will be filled in by cairo_truetype_font_update_entry() after
      * the table is written. */
-    table_buffer_length = ARRAY_LENGTH (truetype_tables) * 16;
+    table_buffer_length = ARRAY_LEN (truetype_tables) * 16;
     status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length,
 						      &table_buffer);
     if (status)
@@ -787,7 +785,7 @@ cairo_truetype_font_generate (cairo_true
     end = start;
 
     end = 0;
-    for (i = 0; i < ARRAY_LENGTH (truetype_tables); i++) {
+    for (i = 0; i < ARRAY_LEN (truetype_tables); i++) {
 	if (truetype_tables[i].write (font, truetype_tables[i].tag))
 	    goto fail;
 
diff --git a/src/cairoint.h b/src/cairoint.h
index 7ce7cd1..6e171e5 100755
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -152,6 +152,9 @@ CAIRO_BEGIN_DECLS
 #define M_PI 3.14159265358979323846
 #endif
 
+#undef  ARRAY_LEN
+#define ARRAY_LEN(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
+
 /* Size in bytes of buffer to use off the stack per functions.
  * Mostly used by text functions.  For larger allocations, they'll
  * malloc(). */
diff-tree 1de12714a9623e66309279eb9edaf6053fd92c56 (from 9b53bc7c6585db7ae647bb992fb9817d7bd75b38)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Mar 14 01:31:58 2007 +0000

    [cairo-surface] Use a stack buffer for small numbers of rectangles

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index ada4b8e..c28b895 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1170,6 +1170,7 @@ _cairo_surface_fill_region (cairo_surfac
 {
     int num_rects = pixman_region_num_rects (region);
     pixman_box16_t *boxes = pixman_region_rects (region);
+    cairo_rectangle_int16_t stack_rects[CAIRO_STACK_BUFFER_SIZE / sizeof (cairo_rectangle_int16_t)];
     cairo_rectangle_int16_t *rects;
     cairo_status_t status;
     int i;
@@ -1179,9 +1180,12 @@ _cairo_surface_fill_region (cairo_surfac
     if (!num_rects)
 	return CAIRO_STATUS_SUCCESS;
 
-    rects = malloc (sizeof (pixman_rectangle_t) * num_rects);
-    if (!rects)
-	return CAIRO_STATUS_NO_MEMORY;
+    rects = stack_rects;
+    if (num_rects > (int) (sizeof (stack_rects) / sizeof (stack_rects[0]))) {
+	rects = malloc (sizeof (cairo_rectangle_int16_t) * num_rects);
+	if (!rects)
+	    return CAIRO_STATUS_NO_MEMORY;
+    }
 
     for (i = 0; i < num_rects; i++) {
 	rects[i].x = boxes[i].x1;
@@ -1193,7 +1197,8 @@ _cairo_surface_fill_region (cairo_surfac
     status =  _cairo_surface_fill_rectangles (surface, op,
 					      color, rects, num_rects);
 
-    free (rects);
+    if (rects != stack_rects)
+	free (rects);
 
     return status;
 }


More information about the cairo-commit mailing list