[cairo-commit] 2 commits - src/cairo-bentley-ottmann.c src/cairo-scaled-font.c

Chris Wilson ickle at kemper.freedesktop.org
Wed Jun 6 00:45:07 PDT 2007


 src/cairo-bentley-ottmann.c |   28 +++++++++++++++-------------
 src/cairo-scaled-font.c     |    2 +-
 2 files changed, 16 insertions(+), 14 deletions(-)

New commits:
diff-tree 2399f923d504fba6b3dcbd0a185cd3d4b29b4dcf (from ecf6f7f5147195276b3b479879cbd3db402df688)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jun 4 19:55:23 2007 +0100

    [cairo-bentley-ottmann] Malloc reduction.
    
    Attempt to allocate the edges during tessellate_polygon() from the stack,
    if the polygon size is sufficiently small and amalgamate the separate
    allocations for the list of events and their sorted index into a single
    block.

diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index bbae875..b8d97fa 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -754,16 +754,14 @@ _cairo_bo_event_queue_init (cairo_bo_eve
      * or stop events, so this allocation is safe.  XXX: make the
      * event type a union so it doesn't always contain the skip
      * elt? */
-    events = malloc (num_events * sizeof(cairo_bo_event_t));
-    sorted_event_ptrs = malloc (num_events * sizeof(cairo_bo_event_t*));
-    if (!events || !sorted_event_ptrs) {
-	if (events) free(events);
-	if (sorted_event_ptrs) free(sorted_event_ptrs);
+    events = malloc (num_events * (sizeof (cairo_bo_event_t) + sizeof(cairo_bo_event_t*)));
+    if (events == NULL)
 	return CAIRO_STATUS_NO_MEMORY;
-    }
+
+    sorted_event_ptrs = (cairo_bo_event_t **) (events + num_events);
     event_queue->startstop_events = events;
     event_queue->sorted_startstop_event_ptrs = sorted_event_ptrs;
-    event_queue->num_startstop_events = (unsigned)(num_events);
+    event_queue->num_startstop_events = num_events;
     event_queue->next_startstop_event_index = 0;
 
     for (i = 0; i < num_edges; i++) {
@@ -796,8 +794,6 @@ _cairo_bo_event_queue_fini (cairo_bo_eve
     _cairo_skip_list_fini (&event_queue->intersection_queue);
     if (event_queue->startstop_events)
 	free (event_queue->startstop_events);
-    if (event_queue->sorted_startstop_event_ptrs)
-	free (event_queue->sorted_startstop_event_ptrs);
 }
 
 static cairo_status_t
@@ -1425,6 +1421,7 @@ _cairo_bentley_ottmann_tessellate_polygo
 {
     int intersections;
     cairo_status_t status;
+    cairo_bo_edge_t stack_edges[CAIRO_STACK_BUFFER_SIZE / sizeof (cairo_bo_edge_t)];
     cairo_bo_edge_t *edges;
     cairo_fixed_t xmin = 0x7FFFFFFF;
     cairo_fixed_t ymin = 0x7FFFFFFF;
@@ -1436,9 +1433,13 @@ _cairo_bentley_ottmann_tessellate_polygo
     if (0 == polygon->num_edges)
 	return CAIRO_STATUS_SUCCESS;
 
-    edges = malloc (polygon->num_edges * sizeof (cairo_bo_edge_t));
-    if (edges == NULL)
-	return CAIRO_STATUS_NO_MEMORY;
+    if (polygon->num_edges < ARRAY_LENGTH (stack_edges)) {
+	edges = stack_edges;
+    } else {
+	edges = malloc (polygon->num_edges * sizeof (cairo_bo_edge_t));
+	if (edges == NULL)
+	    return CAIRO_STATUS_NO_MEMORY;
+    }
 
     /* Figure out the bounding box of the input coordinates and
      * validate that we're not given invalid polygon edges. */
@@ -1518,7 +1519,8 @@ _cairo_bentley_ottmann_tessellate_polygo
 							 xmin, ymin, xmax, ymax,
 							 &intersections);
 
-    free (edges);
+    if (edges != stack_edges)
+	free (edges);
 
     return status;
 }
diff-tree ecf6f7f5147195276b3b479879cbd3db402df688 (from 2e60029392bca904f7035a8f403de0593193b6b9)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jun 4 16:35:15 2007 +0100

    [cairo-scaled-font] Skip the mask composition onto the surface on error.
    
    If we fail to composite the glyph onto the mask, skip compositing the
    mask onto the surface.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index ed30cf3..7a47219 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -1128,7 +1128,7 @@ _cairo_scaled_font_show_glyphs (cairo_sc
 
 	_cairo_pattern_fini (&glyph_pattern.base);
 	if (status)
-	    break;
+	    goto CLEANUP_MASK;
     }
 
     if (mask != NULL) {


More information about the cairo-commit mailing list