[cairo-commit] 10 commits - perf/Makefile.am src/cairo-analysis-surface.c src/cairo-array.c src/cairo-base85-stream.c src/cairo-bentley-ottmann.c src/cairo.c src/cairo-cache.c src/cairo-cff-subset.c src/cairo-clip.c src/cairo-deflate-stream.c src/cairo-directfb-surface.c src/cairo-font-face.c src/cairo-ft-font.c src/cairo-gstate.c src/cairo-hash.c src/cairo-hull.c src/cairo-image-surface.c src/cairo-lzw.c src/cairo-meta-surface.c src/cairo-misc.c src/cairo-output-stream.c src/cairo-paginated-surface.c src/cairo-path.c src/cairo-path-fill.c src/cairo-path-fixed.c src/cairo-path-fixed-private.h src/cairo-path-stroke.c src/cairo-pattern.c src/cairo-pdf-operators.c src/cairo-pdf-surface.c src/cairo-pen.c src/cairo-png.c src/cairo-polygon.c src/cairo-ps-surface.c src/cairo-region.c src/cairo-scaled-font.c src/cairo-scaled-font-subsets.c src/cairo-script-surface.c src/cairo-sdl-surface.c src/cairo-skiplist.c src/cairo-stroke-style.c src/cairo-surface.c src/cairo-surface-fallback.c src/cairo-svg-surface.c src/cairo-traps.c src/cairo-truetype-subset.c src/cairo-type1-fallback.c src/cairo-type1-subset.c src/cairo-type3-glyph-surface.c src/cairo-user-font.c src/cairo-xlib-display.c src/cairo-xlib-screen.c src/cairo-xlib-surface.c src/cairo-xlib-visual.c src/check-doc-syntax.sh src/test-fallback-surface.c src/test-meta-surface.c src/test-paginated-surface.c test/caps.c test/caps-joins.c test/caps-joins-curve.c test/caps-joins-curve.ps.ref.png test/caps-joins-curve.ref.png test/caps-joins.ps2.ref.png test/caps-joins.ps3.ref.png test/caps-joins.ps.ref.png test/caps-joins.ref.png test/caps.ps.ref.png test/caps.ref.png test/dash-curve.ref.png test/device-offset-positive.c test/Makefile.am

Chris Wilson ickle at kemper.freedesktop.org
Sat Nov 29 03:21:05 PST 2008


 dev/null                         |binary
 perf/Makefile.am                 |    3 
 src/cairo-analysis-surface.c     |   28 +-
 src/cairo-array.c                |   10 -
 src/cairo-base85-stream.c        |    2 
 src/cairo-bentley-ottmann.c      |   13 -
 src/cairo-cache.c                |   10 -
 src/cairo-cff-subset.c           |  274 ++++++++++++++---------------
 src/cairo-clip.c                 |   31 +--
 src/cairo-deflate-stream.c       |    2 
 src/cairo-directfb-surface.c     |    2 
 src/cairo-font-face.c            |   20 +-
 src/cairo-ft-font.c              |   69 +++----
 src/cairo-gstate.c               |   83 ++++----
 src/cairo-hash.c                 |    6 
 src/cairo-hull.c                 |    2 
 src/cairo-image-surface.c        |   28 +-
 src/cairo-lzw.c                  |    8 
 src/cairo-meta-surface.c         |   66 +++---
 src/cairo-misc.c                 |   26 +-
 src/cairo-output-stream.c        |   16 -
 src/cairo-paginated-surface.c    |   40 ++--
 src/cairo-path-fill.c            |    8 
 src/cairo-path-fixed-private.h   |   14 -
 src/cairo-path-fixed.c           |   47 +++-
 src/cairo-path-stroke.c          |   60 +++---
 src/cairo-path.c                 |   14 -
 src/cairo-pattern.c              |   70 +++----
 src/cairo-pdf-operators.c        |   66 +++---
 src/cairo-pdf-surface.c          |  368 +++++++++++++++++++--------------------
 src/cairo-pen.c                  |   14 -
 src/cairo-png.c                  |   43 ++--
 src/cairo-polygon.c              |    2 
 src/cairo-ps-surface.c           |  138 +++++++-------
 src/cairo-region.c               |    2 
 src/cairo-scaled-font-subsets.c  |   58 +++---
 src/cairo-scaled-font.c          |  101 +++++-----
 src/cairo-script-surface.c       |  174 +++++++++---------
 src/cairo-sdl-surface.c          |    6 
 src/cairo-skiplist.c             |    2 
 src/cairo-stroke-style.c         |    2 
 src/cairo-surface-fallback.c     |   84 ++++----
 src/cairo-surface.c              |   64 +++---
 src/cairo-svg-surface.c          |  100 +++++-----
 src/cairo-traps.c                |   16 -
 src/cairo-truetype-subset.c      |  128 ++++++-------
 src/cairo-type1-fallback.c       |   59 +++---
 src/cairo-type1-subset.c         |   68 +++----
 src/cairo-type3-glyph-surface.c  |   12 -
 src/cairo-user-font.c            |   20 +-
 src/cairo-xlib-display.c         |    4 
 src/cairo-xlib-screen.c          |    6 
 src/cairo-xlib-surface.c         |  117 ++++++------
 src/cairo-xlib-visual.c          |    2 
 src/cairo.c                      |  142 +++++++--------
 src/check-doc-syntax.sh          |    2 
 src/test-fallback-surface.c      |    2 
 src/test-meta-surface.c          |    2 
 src/test-paginated-surface.c     |    2 
 test/Makefile.am                 |    9 
 test/caps-joins-curve.c          |  111 +++++++++++
 test/caps-joins-curve.ps.ref.png |binary
 test/caps-joins-curve.ref.png    |binary
 test/caps-joins.c                |   40 ++--
 test/caps-joins.ps.ref.png       |binary
 test/caps-joins.ref.png          |binary
 test/caps.c                      |   87 +++++++++
 test/caps.ps.ref.png             |binary
 test/caps.ref.png                |binary
 test/dash-curve.ref.png          |binary
 test/device-offset-positive.c    |    1 
 71 files changed, 1628 insertions(+), 1378 deletions(-)

New commits:
commit 1659db2c1f4cc72e51fb43d119822ec7aaa77ac0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Nov 29 10:37:58 2008 +0000

    [test] Fix surface leak from device-offset-positive.
    
    A forgotten cairo_surface_destroy() caused the similar surface to be
    leaked during the test.

diff --git a/test/device-offset-positive.c b/test/device-offset-positive.c
index 4ea9469..5afe973 100644
--- a/test/device-offset-positive.c
+++ b/test/device-offset-positive.c
@@ -67,6 +67,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_destroy (cr2);
     cairo_surface_set_device_offset (surface, + SIZE / 2, + SIZE / 2);
     cairo_set_source_surface (cr, surface, SIZE / 2, SIZE / 2);
+    cairo_surface_destroy (surface);
 
     cairo_paint (cr);
 
commit 0d757a793d7fe2860c6a522124a123864fc97f0a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Nov 29 10:36:34 2008 +0000

    [png] Fix leak of original png data on error path.
    
    The error path was missing a _cairo_output_stream_destroy() to cleanup a
    copy of the incoming PNG data.

diff --git a/src/cairo-png.c b/src/cairo-png.c
index 301a892..fd16c4d 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -512,6 +512,8 @@ read_png (struct png_read_closure_t *png_closure)
     unsigned char *mime_data;
     unsigned int mime_data_length;
 
+    png_closure->png_data = _cairo_memory_stream_create ();
+
     /* XXX: Perhaps we'll want some other error handlers? */
     png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
                                   &status,
@@ -528,7 +530,6 @@ read_png (struct png_read_closure_t *png_closure)
 	goto BAIL;
     }
 
-    png_closure->png_data = _cairo_memory_stream_create ();
     png_set_read_fn (png, png_closure, stream_read_func);
 
     status = CAIRO_STATUS_SUCCESS;
@@ -659,6 +660,7 @@ read_png (struct png_read_closure_t *png_closure)
 	surface = _cairo_surface_create_in_error (status);
 	goto BAIL;
     }
+    png_closure->png_data = NULL;
 
     status = cairo_surface_set_mime_data (surface,
 					  CAIRO_MIME_TYPE_PNG,
@@ -674,12 +676,17 @@ read_png (struct png_read_closure_t *png_closure)
     }
 
  BAIL:
-    if (row_pointers)
+    if (row_pointers != NULL)
 	free (row_pointers);
-    if (data)
+    if (data != NULL)
 	free (data);
-    if (png)
+    if (png != NULL)
 	png_destroy_read_struct (&png, &info, NULL);
+    if (png_closure->png_data != NULL) {
+	cairo_status_t status_ignored;
+
+	status_ignored = _cairo_output_stream_destroy (png_closure->png_data);
+    }
 
     return surface;
 }
commit e6963a5bfebda69a1ef0a986cede84bcd955b6d4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 18 17:26:55 2008 +0000

    Mark allocation failures as unlikely.
    
    Use the gcc likelihood annotation to indicate that allocation failures are
    extremely unlikely.

diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index 9fb19a8..a19ff10 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -784,7 +784,7 @@ _cairo_analysis_surface_create (cairo_surface_t		*target,
 	return _cairo_surface_create_in_error (status);
 
     surface = malloc (sizeof (cairo_analysis_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     /* I believe the content type here is truly arbitrary. I'm quite
@@ -992,7 +992,7 @@ _cairo_null_surface_create (cairo_content_t content)
     cairo_surface_t *surface;
 
     surface = malloc (sizeof (cairo_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
     }
 
diff --git a/src/cairo-array.c b/src/cairo-array.c
index ef50684..9c084b9 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -138,7 +138,7 @@ _cairo_array_grow_by (cairo_array_t *array, unsigned int additional)
 
     if (array->elements == NULL) {
 	array->elements = malloc (sizeof (char *));
-	if (array->elements == NULL)
+	if (unlikely (array->elements == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	*array->elements = NULL;
@@ -148,7 +148,7 @@ _cairo_array_grow_by (cairo_array_t *array, unsigned int additional)
     new_elements = _cairo_realloc_ab (*array->elements,
 			              array->size, array->element_size);
 
-    if (new_elements == NULL) {
+    if (unlikely (new_elements == NULL)) {
 	array->size = old_size;
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
diff --git a/src/cairo-base85-stream.c b/src/cairo-base85-stream.c
index 4d5a465..9d42ef4 100644
--- a/src/cairo-base85-stream.c
+++ b/src/cairo-base85-stream.c
@@ -117,7 +117,7 @@ _cairo_base85_stream_create (cairo_output_stream_t *output)
 	return _cairo_output_stream_create_in_error (output->status);
 
     stream = malloc (sizeof (cairo_base85_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index eca28d5..cd15021 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -979,7 +979,7 @@ _cairo_bo_event_queue_init (cairo_bo_event_queue_t	*event_queue,
 				      sizeof (cairo_bo_event_t) +
 				      sizeof (cairo_bo_event_t *),
 				      sizeof (cairo_bo_event_t *));
-    if (events == NULL)
+    if (unlikely (events == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     sorted_event_ptrs = (cairo_bo_event_t **) (events + num_events);
@@ -1079,8 +1079,8 @@ _cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t	*sweep_line,
     cairo_bo_edge_t **prev_of_next, **next_of_prev;
 
     sweep_line_elt = _cairo_skip_list_insert (&sweep_line->active_edges, &edge,
-				       1 /* unique inserts*/);
-    if (sweep_line_elt == NULL)
+					      1 /* unique inserts*/);
+    if (unlikely (sweep_line_elt == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     next_elt = sweep_line_elt->elt.next[0];
@@ -1659,11 +1659,10 @@ _cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t	 *traps,
 
     has_limits = _cairo_traps_get_limit (traps, &limit);
 
-    if (polygon->num_edges < ARRAY_LENGTH (stack_edges)) {
-	edges = stack_edges;
-    } else {
+    edges = stack_edges;
+    if (polygon->num_edges > ARRAY_LENGTH (stack_edges)) {
 	edges = _cairo_malloc_ab (polygon->num_edges, sizeof (cairo_bo_edge_t));
-	if (edges == NULL)
+	if (unlikely (edges == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index 7317264..07c8b71 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -53,7 +53,7 @@ _cairo_cache_init (cairo_cache_t		*cache,
 		   unsigned long		 max_size)
 {
     cache->hash_table = _cairo_hash_table_create (keys_equal);
-    if (cache->hash_table == NULL)
+    if (unlikely (cache->hash_table == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     cache->entry_destroy = entry_destroy;
@@ -125,7 +125,7 @@ _cairo_cache_create (cairo_cache_keys_equal_func_t keys_equal,
     cairo_cache_t *cache;
 
     cache = malloc (sizeof (cairo_cache_t));
-    if (cache == NULL) {
+    if (unlikely (cache == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
@@ -240,7 +240,7 @@ _cairo_cache_remove_random (cairo_cache_t *cache)
     cairo_cache_entry_t *entry;
 
     entry = _cairo_hash_table_random_entry (cache->hash_table, NULL);
-    if (entry == NULL)
+    if (unlikely (entry == NULL))
 	return FALSE;
 
     _cairo_cache_remove (cache, entry);
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 2d1fd8f..d1e5a6d 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -399,7 +399,7 @@ cff_index_append_copy (cairo_array_t *index,
     element.length = length;
     element.is_copy = TRUE;
     element.data = malloc (element.length);
-    if (element.data == NULL)
+    if (unlikely (element.data == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     memcpy (element.data, object, element.length);
@@ -440,8 +440,8 @@ static cairo_status_t
 cff_dict_init (cairo_hash_table_t **dict)
 {
     *dict = _cairo_hash_table_create (_cairo_cff_dict_equal);
-    if (*dict == NULL)
-	return CAIRO_STATUS_NO_MEMORY;
+    if (unlikely (*dict == NULL))
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -462,12 +462,12 @@ cff_dict_create_operator (int            operator,
     cff_dict_operator_t *op;
 
     op = malloc (sizeof (cff_dict_operator_t));
-    if (op == NULL)
+    if (unlikely (op == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     _cairo_dict_init_key (op, operator);
     op->operand = malloc (size);
-    if (op->operand == NULL) {
+    if (unlikely (op->operand == NULL)) {
         free (op);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
@@ -568,7 +568,7 @@ cff_dict_set_operands (cairo_hash_table_t *dict,
     if (op != NULL) {
         free (op->operand);
         op->operand = malloc (size);
-	if (op->operand == NULL)
+	if (unlikely (op->operand == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
         memcpy (op->operand, operand, size);
@@ -751,7 +751,7 @@ cairo_cff_font_read_fdselect (cairo_cff_font_t *font, unsigned char *p)
     int type, num_ranges, first, last, fd, i, j;
 
     font->fdselect = calloc (font->num_glyphs, sizeof (int));
-    if (font->fdselect == NULL)
+    if (unlikely (font->fdselect == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     type = *p++;
@@ -799,19 +799,19 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
     font->num_fontdicts = _cairo_array_num_elements (&index);
 
     font->fd_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts);
-    if (font->fd_dict == NULL) {
+    if (unlikely (font->fd_dict == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail;
     }
 
     font->fd_private_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts);
-    if (font->fd_private_dict == NULL) {
+    if (unlikely (font->fd_private_dict == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail;
     }
 
     font->fd_local_sub_index = calloc (sizeof (cairo_array_t), font->num_fontdicts);
-    if (font->fd_local_sub_index == NULL) {
+    if (unlikely (font->fd_local_sub_index == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail;
     }
@@ -1128,19 +1128,19 @@ cairo_cff_font_subset_fontdict (cairo_cff_font_t  *font)
 
     font->fdselect_subset = calloc (font->scaled_font_subset->num_glyphs,
                                      sizeof (int));
-    if (font->fdselect_subset == NULL)
+    if (unlikely (font->fdselect_subset == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->fd_subset_map = calloc (font->num_fontdicts, sizeof (int));
-    if (font->fd_subset_map == NULL)
+    if (unlikely (font->fd_subset_map == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->private_dict_offset = calloc (font->num_fontdicts, sizeof (int));
-    if (font->private_dict_offset == NULL)
+    if (unlikely (font->private_dict_offset == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     reverse_map = calloc (font->num_fontdicts, sizeof (int));
-    if (reverse_map == NULL)
+    if (unlikely (reverse_map == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     for (i = 0; i < font->num_fontdicts; i++)
@@ -1170,7 +1170,7 @@ cairo_cff_font_create_cid_fontdict (cairo_cff_font_t *font)
 
     font->num_fontdicts = 1;
     font->fd_dict = malloc (sizeof (cairo_hash_table_t *));
-    if (font->fd_dict == NULL)
+    if (unlikely (font->fd_dict == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     if (cff_dict_init (&font->fd_dict[0])) {
@@ -1181,11 +1181,11 @@ cairo_cff_font_create_cid_fontdict (cairo_cff_font_t *font)
     }
 
     font->fd_subset_map = malloc (sizeof (int));
-    if (font->fd_subset_map == NULL)
+    if (unlikely (font->fd_subset_map == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->private_dict_offset = malloc (sizeof (int));
-    if (font->private_dict_offset == NULL)
+    if (unlikely (font->private_dict_offset == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->fd_subset_map[0] = 0;
@@ -1757,7 +1757,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
         return status;
 
     name = malloc (size);
-    if (name == NULL)
+    if (unlikely (name == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
@@ -1767,7 +1767,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
         goto fail1;
 
     font = malloc (sizeof (cairo_cff_font_t));
-    if (font == NULL) {
+    if (unlikely (font == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
@@ -1781,7 +1781,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 	goto fail2;
 
     font->subset_font_name = strdup (subset_name);
-    if (font->subset_font_name == NULL) {
+    if (unlikely (font->subset_font_name == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -1817,7 +1817,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 
     if (font->font_name == NULL) {
         font->font_name = malloc (30);
-        if (font->font_name == NULL) {
+        if (unlikely (font->font_name == NULL)) {
             status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
             goto fail3;
         }
@@ -1834,7 +1834,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->font_name[i] = '\0';
 
     font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int));
-    if (font->widths == NULL) {
+    if (unlikely (font->widths == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail4;
     }
@@ -1845,7 +1845,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 
     font->data_length = data_length;
     font->data = malloc (data_length);
-    if (font->data == NULL) {
+    if (unlikely (font->data == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail5;
     }
@@ -1979,13 +1979,13 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
 	goto fail1;
 
     cff_subset->base_font = strdup (font->font_name);
-    if (cff_subset->base_font == NULL) {
+    if (unlikely (cff_subset->base_font == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
 
     cff_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
-    if (cff_subset->widths == NULL) {
+    if (unlikely (cff_subset->widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -2000,7 +2000,7 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
     cff_subset->descent = font->descent;
 
     cff_subset->data = malloc (length);
-    if (cff_subset->data == NULL) {
+    if (unlikely (cff_subset->data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail3;
     }
@@ -2039,7 +2039,7 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
     cairo_cff_font_t *font;
 
     font = malloc (sizeof (cairo_cff_font_t));
-    if (font == NULL)
+    if (unlikely (font == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->backend = NULL;
@@ -2051,13 +2051,13 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
 	goto fail1;
 
     font->subset_font_name = strdup (subset_name);
-    if (font->subset_font_name == NULL) {
+    if (unlikely (font->subset_font_name == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
 
     font->font_name = strdup (subset_name);
-    if (font->subset_font_name == NULL) {
+    if (unlikely (font->subset_font_name == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -2070,7 +2070,7 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
     font->descent = 0;
 
     font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int));
-    if (font->widths == NULL) {
+    if (unlikely (font->widths == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail3;
     }
@@ -2227,13 +2227,13 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
 	goto fail2;
 
     cff_subset->base_font = strdup (font->font_name);
-    if (cff_subset->base_font == NULL) {
+    if (unlikely (cff_subset->base_font == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
 
     cff_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
-    if (cff_subset->widths == NULL) {
+    if (likely (cff_subset->widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail3;
     }
@@ -2248,7 +2248,7 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
     cff_subset->descent = type2_subset.y_min;
 
     cff_subset->data = malloc (length);
-    if (cff_subset->data == NULL) {
+    if (likely (cff_subset->data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail4;
     }
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 5c197ff..35082f9 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -298,7 +298,7 @@ _cairo_clip_intersect_path (cairo_clip_t       *clip,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     clip_path = malloc (sizeof (cairo_clip_path_t));
-    if (clip_path == NULL)
+    if (likely (clip_path == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_path_fixed_init_copy (&clip_path->path, path);
@@ -759,7 +759,7 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
 
 	if (n_boxes) {
 	    rectangles = _cairo_malloc_ab (n_boxes, sizeof (cairo_rectangle_t));
-	    if (rectangles == NULL) {
+	    if (unlikely (rectangles == NULL)) {
 		_cairo_region_boxes_fini (&clip->region, boxes);
 		_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 		return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
@@ -789,7 +789,7 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
 	n_boxes = 1;
 
 	rectangles = malloc(sizeof (cairo_rectangle_t));
-	if (rectangles == NULL) {
+	if (unlikely (rectangles == NULL)) {
 	    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	    return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 	}
@@ -805,7 +805,7 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
 
  DONE:
     list = malloc (sizeof (cairo_rectangle_list_t));
-    if (list == NULL) {
+    if (unlikely (list == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
         free (rectangles);
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
diff --git a/src/cairo-deflate-stream.c b/src/cairo-deflate-stream.c
index 3bb884c..863189f 100644
--- a/src/cairo-deflate-stream.c
+++ b/src/cairo-deflate-stream.c
@@ -121,7 +121,7 @@ _cairo_deflate_stream_create (cairo_output_stream_t *output)
 	return _cairo_output_stream_create_in_error (output->status);
 
     stream = malloc (sizeof (cairo_deflate_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 8cbd3bc..cab7104 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -455,7 +455,7 @@ _cairo_directfb_surface_create_similar (void            *abstract_src,
 
     format = _cairo_format_from_content (content);
     surface = calloc (1, sizeof (cairo_directfb_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     surface->dfb = source->dfb;
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c
index 0637758..a78c2aa 100644
--- a/src/cairo-font-face.c
+++ b/src/cairo-font-face.c
@@ -398,7 +398,7 @@ _cairo_toy_font_face_init (cairo_toy_font_face_t *font_face,
     char *family_copy;
 
     family_copy = strdup (family);
-    if (family_copy == NULL)
+    if (unlikely (family_copy == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     _cairo_toy_font_face_init_key (font_face, family_copy,
@@ -495,7 +495,7 @@ cairo_toy_font_face_create (const char          *family,
 	family = CAIRO_FONT_FAMILY_DEFAULT;
 
     hash_table = _cairo_toy_font_face_hash_table_lock ();
-    if (hash_table == NULL)
+    if (unlikely (hash_table == NULL))
 	goto UNWIND;
 
     _cairo_toy_font_face_init_key (&key, family, slant, weight);
@@ -519,7 +519,7 @@ cairo_toy_font_face_create (const char          *family,
 
     /* Otherwise create it and insert into hash table. */
     font_face = malloc (sizeof (cairo_toy_font_face_t));
-    if (font_face == NULL) {
+    if (unlikely (font_face == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNWIND_HASH_TABLE_LOCK;
     }
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index a8d4101..773f6ea 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -182,7 +182,7 @@ _cairo_ft_unscaled_font_map_create (void)
     assert (cairo_ft_unscaled_font_map == NULL);
 
     font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t));
-    if (font_map == NULL) {
+    if (unlikely (font_map == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
@@ -190,7 +190,7 @@ _cairo_ft_unscaled_font_map_create (void)
     font_map->hash_table =
 	_cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal);
 
-    if (font_map->hash_table == NULL)
+    if (unlikely (font_map->hash_table == NULL))
 	goto FAIL;
 
     if (FT_Init_FreeType (&font_map->ft_library))
@@ -261,7 +261,7 @@ _cairo_ft_unscaled_font_map_lock (void)
     {
 	_cairo_ft_unscaled_font_map_create ();
 
-	if (cairo_ft_unscaled_font_map == NULL) {
+	if (unlikely (cairo_ft_unscaled_font_map == NULL)) {
 	    CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex);
 	    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	    return NULL;
@@ -340,8 +340,9 @@ _cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
 	unscaled->face = NULL;
 
 	filename_copy = strdup (filename);
-	if (filename_copy == NULL)
+	if (unlikely (filename_copy == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
 	_cairo_ft_unscaled_font_init_key (unscaled, FALSE, filename_copy, id, NULL);
     }
 
@@ -416,7 +417,7 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face,
     cairo_status_t status;
 
     font_map = _cairo_ft_unscaled_font_map_lock ();
-    if (font_map == NULL)
+    if (unlikely (font_map == NULL))
 	goto UNWIND;
 
     _cairo_ft_unscaled_font_init_key (&key, from_face, filename, id, font_face);
@@ -432,7 +433,7 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face,
 
     /* Otherwise create it and insert into hash table. */
     unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
-    if (unscaled == NULL) {
+    if (unlikely (unscaled == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	goto UNWIND_FONT_MAP_LOCK;
     }
@@ -874,7 +875,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	    stride = bitmap->pitch;
 	    stride_rgba = (width_rgba * 4 + 3) & ~3;
 	    data_rgba = calloc (stride_rgba, height);
-	    if (data_rgba == NULL) {
+	    if (unlikely (data_rgba == NULL)) {
 		if (own_buffer)
 		    free (bitmap->buffer);
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1073,7 +1074,7 @@ _render_glyph_outline (FT_Face                    face,
 	bitmap.width = width * hmul;
 	bitmap.rows = height * vmul;
 	bitmap.buffer = calloc (stride, bitmap.rows);
-	if (bitmap.buffer == NULL)
+	if (unlikely (bitmap.buffer == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul);
@@ -1512,7 +1513,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t	 *unscaled,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     scaled_font = malloc (sizeof(cairo_ft_scaled_font_t));
-    if (scaled_font == NULL) {
+    if (unlikely (scaled_font == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
@@ -2532,7 +2533,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
     cairo_ft_options_t ft_options;
 
     unscaled = _cairo_ft_unscaled_font_create_for_pattern (pattern);
-    if (unscaled == NULL) {
+    if (unlikely (unscaled == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_font_face_t *)&_cairo_font_face_nil;
     }
@@ -2599,7 +2600,7 @@ cairo_ft_font_face_create_for_ft_face (FT_Face         face,
     cairo_ft_options_t ft_options;
 
     unscaled = _cairo_ft_unscaled_font_create_from_face (face);
-    if (unscaled == NULL) {
+    if (unlikely (unscaled == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_font_face_t *)&_cairo_font_face_nil;
     }
@@ -2660,7 +2661,7 @@ cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font)
 	return NULL;
 
     face = _cairo_ft_unscaled_font_lock_face (scaled_font->unscaled);
-    if (face == NULL) {
+    if (unlikely (face == NULL)) {
 	status = _cairo_scaled_font_set_error (&scaled_font->base, CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index d7d91c9..09161aa 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -221,7 +221,7 @@ _cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist)
     top = *freelist;
     if (top == NULL) {
 	top = malloc (sizeof (cairo_gstate_t));
-	if (top == NULL)
+	if (unlikely (top == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else
 	*freelist = top->next;
@@ -512,7 +512,7 @@ _cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dash
     }
 
     gstate->stroke_style.dash = _cairo_malloc_ab (gstate->stroke_style.num_dashes, sizeof (double));
-    if (gstate->stroke_style.dash == NULL) {
+    if (unlikely (gstate->stroke_style.dash == NULL)) {
 	gstate->stroke_style.num_dashes = 0;
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
@@ -1615,7 +1615,7 @@ _cairo_gstate_show_text_glyphs (cairo_gstate_t		   *gstate,
 	transformed_glyphs = stack_transformed_glyphs;
     } else {
 	transformed_glyphs = cairo_glyph_allocate (num_glyphs);
-	if (transformed_glyphs == NULL)
+	if (unlikely (transformed_glyphs == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
@@ -1701,12 +1701,13 @@ _cairo_gstate_glyph_path (cairo_gstate_t      *gstate,
     if (unlikely (status))
 	return status;
 
-    if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs))
+    if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs)) {
       transformed_glyphs = stack_transformed_glyphs;
-    else
-      transformed_glyphs = cairo_glyph_allocate (num_glyphs);
-    if (transformed_glyphs == NULL)
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    } else {
+	transformed_glyphs = cairo_glyph_allocate (num_glyphs);
+	if (unlikely (transformed_glyphs == NULL))
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    }
 
     status = _cairo_gstate_transform_glyphs_to_backend (gstate,
 							glyphs, num_glyphs,
diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index b3f43b0..973281d 100644
--- a/src/cairo-hash.c
+++ b/src/cairo-hash.c
@@ -148,7 +148,7 @@ _cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal)
     cairo_hash_table_t *hash_table;
 
     hash_table = malloc (sizeof (cairo_hash_table_t));
-    if (hash_table == NULL) {
+    if (unlikely (hash_table == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
@@ -159,7 +159,7 @@ _cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal)
 
     hash_table->entries = calloc (hash_table->arrangement->size,
 				  sizeof(cairo_hash_entry_t *));
-    if (hash_table->entries == NULL) {
+    if (unlikely (hash_table->entries == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	free (hash_table);
 	return NULL;
@@ -280,7 +280,7 @@ _cairo_hash_table_resize (cairo_hash_table_t *hash_table)
 
     new_size = tmp.arrangement->size;
     tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*));
-    if (tmp.entries == NULL)
+    if (unlikely (tmp.entries == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     for (i = 0; i < hash_table->arrangement->size; ++i) {
diff --git a/src/cairo-hull.c b/src/cairo-hull.c
index 008ba7f..a699a52 100644
--- a/src/cairo-hull.c
+++ b/src/cairo-hull.c
@@ -200,7 +200,7 @@ _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices)
 
     if (num_hull > ARRAY_LENGTH (hull_stack)) {
 	hull = _cairo_malloc_ab (num_hull, sizeof (cairo_hull_t));
-	if (hull == NULL)
+	if (unlikely (hull == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else {
 	hull = hull_stack;
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index ab8ab5e..2bf4543 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -131,7 +131,7 @@ _cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
     cairo_image_surface_t *surface;
 
     surface = malloc (sizeof (cairo_image_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&surface->base, &_cairo_image_surface_backend,
@@ -327,7 +327,7 @@ _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
     pixman_image = pixman_image_create_bits (pixman_format, width, height,
 					     (uint32_t *) data, stride);
 
-    if (pixman_image == NULL)
+    if (unlikely (pixman_image == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     surface = _cairo_image_surface_create_for_pixman_image (pixman_image,
@@ -1051,7 +1051,7 @@ _cairo_image_surface_fill_rectangles (void		      *abstract_surface,
 
     if (num_rects > ARRAY_LENGTH (stack_rects)) {
 	pixman_rects = _cairo_malloc_ab (num_rects, sizeof (pixman_rectangle16_t));
-	if (pixman_rects == NULL)
+	if (unlikely (pixman_rects == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
@@ -1110,7 +1110,7 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
     /* Convert traps to pixman traps */
     if (num_traps > ARRAY_LENGTH (stack_traps)) {
 	pixman_traps = _cairo_malloc_ab (num_traps, sizeof (pixman_trapezoid_t));
-	if (pixman_traps == NULL)
+	if (unlikely (pixman_traps == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
@@ -1181,14 +1181,14 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
 
     /* The image must be initially transparent */
     mask_data = calloc (mask_stride, height);
-    if (mask_data == NULL) {
+    if (unlikely (mask_data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP_SOURCE;
     }
 
     mask = pixman_image_create_bits (format, width, height,
 				     mask_data, mask_stride);
-    if (mask == NULL) {
+    if (unlikely (mask == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP_IMAGE_DATA;
     }
diff --git a/src/cairo-lzw.c b/src/cairo-lzw.c
index c179176..a4fdf73 100644
--- a/src/cairo-lzw.c
+++ b/src/cairo-lzw.c
@@ -73,7 +73,7 @@ _lzw_buf_init (lzw_buf_t *buf, int size)
     buf->pending_bits = 0;
 
     buf->data = malloc (size);
-    if (buf->data == NULL) {
+    if (unlikely (buf->data == NULL)) {
 	buf->data_size = 0;
 	buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return;
@@ -98,7 +98,7 @@ _lzw_buf_grow (lzw_buf_t *buf)
     if (new_size / 2 == buf->data_size)
 	new_data = realloc (buf->data, new_size);
 
-    if (new_data == NULL) {
+    if (unlikely (new_data == NULL)) {
 	free (buf->data);
 	buf->data_size = 0;
 	buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index f32f489..e69df21 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -84,7 +84,7 @@ _cairo_meta_surface_create (cairo_content_t	content,
     cairo_meta_surface_t *meta;
 
     meta = malloc (sizeof (cairo_meta_surface_t));
-    if (meta == NULL)
+    if (unlikely (meta == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&meta->base, &cairo_meta_surface_backend,
@@ -227,7 +227,7 @@ _cairo_meta_surface_paint (void			*abstract_surface,
     cairo_command_paint_t *command;
 
     command = malloc (sizeof (cairo_command_paint_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_PAINT;
@@ -273,7 +273,7 @@ _cairo_meta_surface_mask (void			*abstract_surface,
     cairo_command_mask_t *command;
 
     command = malloc (sizeof (cairo_command_mask_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_MASK;
@@ -324,7 +324,7 @@ _cairo_meta_surface_stroke (void			*abstract_surface,
     cairo_command_stroke_t *command;
 
     command = malloc (sizeof (cairo_command_stroke_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_STROKE;
@@ -384,7 +384,7 @@ _cairo_meta_surface_fill (void			*abstract_surface,
     cairo_command_fill_t *command;
 
     command = malloc (sizeof (cairo_command_fill_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_FILL;
@@ -447,7 +447,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
     cairo_command_show_text_glyphs_t *command;
 
     command = malloc (sizeof (cairo_command_show_text_glyphs_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_SHOW_TEXT_GLYPHS;
@@ -471,7 +471,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
 
     if (utf8_len) {
 	command->utf8 = malloc (utf8_len);
-	if (command->utf8 == NULL) {
+	if (unlikely (command->utf8 == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP_ARRAYS;
 	}
@@ -479,7 +479,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
     }
     if (num_glyphs) {
 	command->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (glyphs[0]));
-	if (command->glyphs == NULL) {
+	if (unlikely (command->glyphs == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP_ARRAYS;
 	}
@@ -487,7 +487,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
     }
     if (num_clusters) {
 	command->clusters = _cairo_malloc_ab (num_clusters, sizeof (clusters[0]));
-	if (command->clusters == NULL) {
+	if (unlikely (command->clusters == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP_ARRAYS;
 	}
@@ -537,7 +537,7 @@ _cairo_meta_surface_snapshot (void *abstract_other)
     cairo_meta_surface_t *meta;
 
     meta = malloc (sizeof (cairo_meta_surface_t));
-    if (meta == NULL)
+    if (unlikely (meta == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&meta->base, &cairo_meta_surface_backend,
@@ -567,7 +567,7 @@ _cairo_meta_surface_intersect_clip_path (void		    *dst,
     cairo_status_t status;
 
     command = malloc (sizeof (cairo_command_intersect_clip_path_t));
-    if (command == NULL)
+    if (unlikely (command == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     command->header.type = CAIRO_COMMAND_INTERSECT_CLIP_PATH;
@@ -930,7 +930,7 @@ _cairo_meta_surface_replay_internal (cairo_surface_t	     *surface,
 	     * copy the array before handing it to the backend.
 	     */
 	    dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
-	    if (dev_glyphs == NULL) {
+	    if (unlikely (dev_glyphs == NULL)) {
 		status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		break;
 	    }
diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index c487603..6f707a6 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -714,14 +714,19 @@ _cairo_intern_string (const char **str_inout, int len)
     tmpl.string = (char *) str;
 
     CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex);
-    if (_cairo_intern_string_ht == NULL)
+    if (_cairo_intern_string_ht == NULL) {
 	_cairo_intern_string_ht = _cairo_hash_table_create (_intern_string_equal);
+	if (unlikely (_cairo_intern_string_ht == NULL)) {
+	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto BAIL;
+	}
+    }
 
     istring = _cairo_hash_table_lookup (_cairo_intern_string_ht,
 					&tmpl.hash_entry);
     if (istring == NULL) {
 	istring = malloc (sizeof (cairo_intern_string_t) + len + 1);
-	if (istring != NULL) {
+	if (likely (istring != NULL)) {
 	    istring->hash_entry.hash = tmpl.hash_entry.hash;
 	    istring->len = tmpl.len;
 	    istring->string = (char *) (istring + 1);
@@ -730,17 +735,20 @@ _cairo_intern_string (const char **str_inout, int len)
 
 	    status = _cairo_hash_table_insert (_cairo_intern_string_ht,
 					       &istring->hash_entry);
-	    if (unlikely (status))
+	    if (unlikely (status)) {
 		free (istring);
-	} else
+		goto BAIL;
+	    }
+	} else {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto BAIL;
+	}
     }
 
-    CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex);
-
-    if (likely (status == CAIRO_STATUS_SUCCESS))
-	*str_inout = istring->string;
+    *str_inout = istring->string;
 
+  BAIL:
+    CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex);
     return status;
 }
 
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index 780bd50..7115433 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -147,7 +147,7 @@ _cairo_output_stream_create (cairo_write_func_t		write_func,
     cairo_output_stream_with_closure_t *stream;
 
     stream = malloc (sizeof (cairo_output_stream_with_closure_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -173,7 +173,7 @@ _cairo_output_stream_create_in_error (cairo_status_t status)
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error;
 
     stream = malloc (sizeof (cairo_output_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -598,7 +598,7 @@ _cairo_output_stream_create_for_file (FILE *file)
     }
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -632,7 +632,7 @@ _cairo_output_stream_create_for_filename (const char *filename)
     }
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	fclose (file);
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
@@ -676,7 +676,7 @@ _cairo_memory_stream_create (void)
     memory_stream_t *stream;
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -703,7 +703,7 @@ _cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream,
 
     *length_out = _cairo_array_num_elements (&stream->array);
     *data_out = malloc (*length_out);
-    if (*data_out == NULL) {
+    if (unlikely (*data_out == NULL)) {
 	status = _cairo_output_stream_destroy (abstract_stream);
 	assert (status == CAIRO_STATUS_SUCCESS);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -753,7 +753,7 @@ _cairo_null_stream_create (void)
     cairo_output_stream_t *stream;
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 70b728e..2b58e49 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -77,7 +77,7 @@ _cairo_paginated_surface_create (cairo_surface_t				*target,
     cairo_status_t status;
 
     surface = malloc (sizeof (cairo_paginated_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 04d547c..2f36562 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -120,7 +120,7 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
     buf_size = MAX (num_ops, (num_points + 1) / 2);
     if (buf_size) {
 	buf = _cairo_path_buf_create (buf_size);
-	if (buf == NULL) {
+	if (unlikely (buf == NULL)) {
 	    _cairo_path_fixed_fini (path);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
@@ -557,7 +557,7 @@ _cairo_path_fixed_add (cairo_path_fixed_t *path,
 	buf->num_points + num_points > 2 * buf->buf_size)
     {
 	buf = _cairo_path_buf_create (buf->buf_size * 2);
-	if (buf == NULL)
+	if (unlikely (buf == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	_cairo_path_fixed_add_buf (path, buf);
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index f2b9e7a..8c3064e 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -1254,7 +1254,7 @@ _cairo_rectilinear_stroker_add_segment (cairo_rectilinear_stroker_t	*stroker,
 
 	if (stroker->segments == stroker->segments_embedded) {
 	    new_segments = _cairo_malloc_ab (new_size, sizeof (cairo_line_t));
-	    if (new_segments == NULL)
+	    if (unlikely (new_segments == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	    memcpy (new_segments, stroker->segments,
@@ -1262,7 +1262,7 @@ _cairo_rectilinear_stroker_add_segment (cairo_rectilinear_stroker_t	*stroker,
 	} else {
 	    new_segments = _cairo_realloc_ab (stroker->segments,
 					      new_size, sizeof (cairo_line_t));
-	    if (new_segments == NULL)
+	    if (unlikely (new_segments == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
diff --git a/src/cairo-path.c b/src/cairo-path.c
index 855b85f..84dfc0c 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -302,7 +302,7 @@ _cairo_path_create_in_error (cairo_status_t status)
 	return (cairo_path_t*) &_cairo_path_nil;
 
     path = malloc (sizeof (cairo_path_t));
-    if (path == NULL) {
+    if (unlikely (path == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_path_t*) &_cairo_path_nil;
     }
@@ -322,7 +322,7 @@ _cairo_path_create_internal (cairo_path_fixed_t *path_fixed,
     cairo_path_t *path;
 
     path = malloc (sizeof (cairo_path_t));
-    if (path == NULL) {
+    if (unlikely (path == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_path_t*) &_cairo_path_nil;
     }
@@ -337,8 +337,8 @@ _cairo_path_create_internal (cairo_path_fixed_t *path_fixed,
 
     if (path->num_data) {
 	path->data = _cairo_malloc_ab (path->num_data,
-	       	                       sizeof (cairo_path_data_t));
-	if (path->data == NULL) {
+				       sizeof (cairo_path_data_t));
+	if (unlikely (path->data == NULL)) {
 	    free (path);
 	    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	    return (cairo_path_t*) &_cairo_path_nil;
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 56fa28a..aa580d5 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -140,7 +140,7 @@ _cairo_gradient_pattern_init_copy (cairo_gradient_pattern_t	  *pattern,
     {
 	pattern->stops = _cairo_malloc_ab (other->stops_size,
 					   sizeof (cairo_gradient_stop_t));
-	if (pattern->stops == NULL) {
+	if (unlikely (pattern->stops == NULL)) {
 	    pattern->stops_size = 0;
 	    pattern->n_stops = 0;
 	    return _cairo_pattern_set_error (&pattern->base, CAIRO_STATUS_NO_MEMORY);
@@ -272,7 +272,7 @@ _cairo_pattern_create_copy (cairo_pattern_t	  **pattern,
 	*pattern = malloc (sizeof (cairo_radial_pattern_t));
 	break;
     }
-    if (*pattern == NULL)
+    if (unlikely (*pattern == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_pattern_init_copy (*pattern, other);
@@ -379,18 +379,17 @@ _cairo_pattern_create_solid (const cairo_color_t *color,
 
     CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_pattern_cache_lock);
 
-    if (pattern == NULL) {
+    if (unlikely (pattern == NULL)) {
 	/* None cached, need to create a new pattern. */
 	pattern = malloc (sizeof (cairo_solid_pattern_t));
+	if (unlikely (pattern == NULL)) {
+	    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
+	    return (cairo_pattern_t *) &_cairo_pattern_nil;
+	}
     }
 
-    if (pattern == NULL) {
-	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
-	pattern = (cairo_solid_pattern_t *) &_cairo_pattern_nil;
-    } else {
-	_cairo_pattern_init_solid (pattern, color, content);
-	CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1);
-    }
+    _cairo_pattern_init_solid (pattern, color, content);
+    CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1);
 
     return &pattern->base;
 }
@@ -535,7 +534,7 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface)
 	return (cairo_pattern_t*) _cairo_pattern_create_in_error (surface->status);
 
     pattern = malloc (sizeof (cairo_surface_pattern_t));
-    if (pattern == NULL) {
+    if (unlikely (pattern == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_pattern_t *)&_cairo_pattern_nil.base;
     }
@@ -581,7 +580,7 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1)
     cairo_linear_pattern_t *pattern;
 
     pattern = malloc (sizeof (cairo_linear_pattern_t));
-    if (pattern == NULL) {
+    if (unlikely (pattern == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_pattern_t *) &_cairo_pattern_nil.base;
     }
@@ -629,7 +628,7 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0,
     cairo_radial_pattern_t *pattern;
 
     pattern = malloc (sizeof (cairo_radial_pattern_t));
-    if (pattern == NULL) {
+    if (unlikely (pattern == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_pattern_t *) &_cairo_pattern_nil.base;
     }
@@ -846,11 +845,11 @@ _cairo_pattern_gradient_grow (cairo_gradient_pattern_t *pattern)
 	    memcpy (new_stops, pattern->stops, old_size * sizeof (cairo_gradient_stop_t));
     } else {
 	new_stops = _cairo_realloc_ab (pattern->stops,
-	       	                       new_size,
+				       new_size,
 				       sizeof (cairo_gradient_stop_t));
     }
 
-    if (new_stops == NULL)
+    if (unlikely (new_stops == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     pattern->stops = new_stops;
@@ -1255,8 +1254,9 @@ _cairo_pattern_acquire_surface_for_gradient (const cairo_gradient_pattern_t *pat
     cairo_matrix_t matrix = pattern->base.matrix;
 
     if (pattern->n_stops > ARRAY_LENGTH(pixman_stops_static)) {
-	pixman_stops = _cairo_malloc_ab (pattern->n_stops, sizeof(pixman_gradient_stop_t));
-	if (pixman_stops == NULL)
+	pixman_stops = _cairo_malloc_ab (pattern->n_stops,
+					 sizeof(pixman_gradient_stop_t));
+	if (unlikely (pixman_stops == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
@@ -1340,7 +1340,7 @@ _cairo_pattern_acquire_surface_for_gradient (const cairo_gradient_pattern_t *pat
     if (pixman_stops != pixman_stops_static)
 	free (pixman_stops);
 
-    if (pixman_image == NULL)
+    if (unlikely (pixman_image == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     if (_cairo_surface_is_image (dst))
diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 9d5bcba..ea5c514 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -301,7 +301,7 @@ _word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
 	return _cairo_output_stream_create_in_error (output->status);
 
     stream = malloc (sizeof (word_wrap_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -569,7 +569,7 @@ _cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t	*pdf_operators,
 	 */
 	if (num_dashes % 2) {
 	    dash = _cairo_malloc_abc (num_dashes, 2, sizeof (double));
-	    if (dash == NULL)
+	    if (unlikely (dash == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	    memcpy (dash, style->dash, num_dashes * sizeof (double));
@@ -585,7 +585,7 @@ _cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t	*pdf_operators,
 		 */
 		if (dash == style->dash) {
 		    dash = _cairo_malloc_ab (num_dashes, sizeof (double));
-		    if (dash == NULL)
+		    if (unlikely (dash == NULL))
 			return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		    memcpy (dash, style->dash, num_dashes * sizeof (double));
 		}
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 9926e6f..b85a6c8 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -249,7 +249,7 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t	*output,
     cairo_status_t status, status_ignored;
 
     surface = malloc (sizeof (cairo_pdf_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	/* destroy stream on behalf of caller */
 	status = _cairo_output_stream_destroy (output);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
@@ -817,7 +817,7 @@ _cairo_pdf_surface_create_smask_group (cairo_pdf_surface_t	*surface)
     cairo_pdf_smask_group_t	*group;
 
     group = calloc (1, sizeof (cairo_pdf_smask_group_t));
-    if (group == NULL) {
+    if (unlikely (group == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
@@ -1461,7 +1461,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t	*surface,
 	alpha = _cairo_malloc_ab (image->height, image->width);
     }
 
-    if (alpha == NULL) {
+    if (unlikely (alpha == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
@@ -1557,7 +1557,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
 
     rgb_size = image->height * image->width * 3;
     rgb = _cairo_malloc_abc (image->width, image->height, 3);
-    if (rgb == NULL) {
+    if (unlikely (rgb == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
@@ -2333,7 +2333,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t      *surface,
     alpha_function->id = 0;
 
     allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_pdf_color_stop_t));
-    if (allstops == NULL)
+    if (unlikely (allstops == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     stops = &allstops[1];
@@ -3857,11 +3857,11 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
 	return CAIRO_STATUS_SUCCESS;
 
     glyphs = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (cairo_pdf_resource_t));
-    if (glyphs == NULL)
+    if (unlikely (glyphs == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     widths = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (double));
-    if (widths == NULL) {
+    if (unlikely (widths == NULL)) {
         free (glyphs);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
@@ -4171,7 +4171,7 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 
     if (gstate_res.id != 0) {
 	smask_group = _cairo_pdf_surface_create_smask_group (surface);
-	if (smask_group == NULL)
+	if (unlikely (smask_group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	smask_group->operation = PDF_PAINT;
@@ -4227,7 +4227,7 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 
     if (gstate_res.id != 0) {
 	smask_group = _cairo_pdf_surface_create_smask_group (surface);
-	if (smask_group == NULL)
+	if (unlikely (smask_group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	smask_group->operation = PDF_PAINT;
@@ -4740,7 +4740,7 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
-	if (group == NULL)
+	if (unlikely (group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	group->operation = PDF_PAINT;
@@ -4823,7 +4823,7 @@ _cairo_pdf_surface_mask	(void			*abstract_surface,
     assert (_cairo_pdf_surface_operation_supported (surface, op, mask));
 
     group = _cairo_pdf_surface_create_smask_group (surface);
-    if (group == NULL)
+    if (unlikely (group == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     group->operation = PDF_MASK;
@@ -4902,7 +4902,7 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
-	if (group == NULL)
+	if (unlikely (group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	group->operation = PDF_STROKE;
@@ -5000,7 +5000,7 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
 
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
-	if (group == NULL)
+	if (unlikely (group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	group->operation = PDF_FILL;
@@ -5190,7 +5190,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
-	if (group == NULL)
+	if (unlikely (group == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	group->operation = PDF_SHOW_GLYPHS;
@@ -5203,7 +5203,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
 	if (utf8_len) {
 	    group->utf8 = malloc (utf8_len);
-	    if (group->utf8 == NULL) {
+	    if (unlikely (group->utf8 == NULL)) {
 		_cairo_pdf_smask_group_destroy (group);
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
@@ -5213,7 +5213,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
 	if (num_glyphs) {
 	    group->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
-	    if (group->glyphs == NULL) {
+	    if (unlikely (group->glyphs == NULL)) {
 		_cairo_pdf_smask_group_destroy (group);
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
@@ -5223,7 +5223,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
 	if (num_clusters) {
 	    group->clusters = _cairo_malloc_ab (num_clusters, sizeof (cairo_text_cluster_t));
-	    if (group->clusters == NULL) {
+	    if (unlikely (group->clusters == NULL)) {
 		_cairo_pdf_smask_group_destroy (group);
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 21ed8e3..4158f17 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -65,7 +65,7 @@ _cairo_pen_init (cairo_pen_t	*pen,
     if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) {
 	pen->vertices = _cairo_malloc_ab (pen->num_vertices,
 					  sizeof (cairo_pen_vertex_t));
-	if (pen->vertices == NULL)
+	if (unlikely (pen->vertices == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else {
 	pen->vertices = pen->vertices_embedded;
@@ -112,7 +112,7 @@ _cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other)
 	if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) {
 	    pen->vertices = _cairo_malloc_ab (pen->num_vertices,
 					      sizeof (cairo_pen_vertex_t));
-	    if (pen->vertices == NULL)
+	    if (unlikely (pen->vertices == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
@@ -139,7 +139,7 @@ _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
 	if (pen->vertices == pen->vertices_embedded) {
 	    vertices = _cairo_malloc_ab (num_vertices,
 		                         sizeof (cairo_pen_vertex_t));
-	    if (vertices == NULL)
+	    if (unlikely (vertices == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	    memcpy (vertices, pen->vertices,
@@ -148,7 +148,7 @@ _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
 	    vertices = _cairo_realloc_ab (pen->vertices,
 					  num_vertices,
 					  sizeof (cairo_pen_vertex_t));
-	    if (vertices == NULL)
+	    if (unlikely (vertices == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
diff --git a/src/cairo-png.c b/src/cairo-png.c
index 69df0f3..301a892 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -169,7 +169,7 @@ write_png (cairo_surface_t	*surface,
     }
 
     rows = _cairo_malloc_ab (image->height, sizeof (png_byte*));
-    if (rows == NULL) {
+    if (unlikely (rows == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL1;
     }
@@ -180,13 +180,13 @@ write_png (cairo_surface_t	*surface,
     png = png_create_write_struct (PNG_LIBPNG_VER_STRING, &status,
 	                           png_simple_error_callback,
 	                           png_simple_warning_callback);
-    if (png == NULL) {
+    if (unlikely (png == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL2;
     }
 
     info = png_create_info_struct (png);
-    if (info == NULL) {
+    if (unlikely (info == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL3;
     }
@@ -517,13 +517,13 @@ read_png (struct png_read_closure_t *png_closure)
                                   &status,
 	                          png_simple_error_callback,
 	                          png_simple_warning_callback);
-    if (png == NULL) {
+    if (unlikely (png == NULL)) {
 	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	goto BAIL;
     }
 
     info = png_create_info_struct (png);
-    if (info == NULL) {
+    if (unlikely (info == NULL)) {
 	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	goto BAIL;
     }
@@ -620,13 +620,13 @@ read_png (struct png_read_closure_t *png_closure)
     }
 
     data = _cairo_malloc_ab (png_height, stride);
-    if (data == NULL) {
+    if (unlikely (data == NULL)) {
 	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	goto BAIL;
     }
 
     row_pointers = _cairo_malloc_ab (png_height, sizeof (char *));
-    if (row_pointers == NULL) {
+    if (unlikely (row_pointers == NULL)) {
 	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	goto BAIL;
     }
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 95cadc9..0b0fa99 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -73,7 +73,7 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
 		                       new_size, sizeof (cairo_edge_t));
     }
 
-    if (new_edges == NULL) {
+    if (unlikely (new_edges == NULL)) {
 	polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return FALSE;
     }
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 43219e5..9d2a7c5 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -705,7 +705,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
     cairo_ps_surface_t *surface;
 
     surface = malloc (sizeof (cairo_ps_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
@@ -734,7 +734,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
 	goto CLEANUP_OUTPUT_STREAM;
 
     surface->font_subsets = _cairo_scaled_font_subsets_create_simple ();
-    if (surface->font_subsets == NULL) {
+    if (unlikely (surface->font_subsets == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP_OUTPUT_STREAM;
     }
@@ -1201,7 +1201,7 @@ cairo_ps_surface_dsc_comment (cairo_surface_t	*surface,
 
     /* Then, copy the comment and store it in the appropriate array. */
     comment_copy = strdup (comment);
-    if (comment_copy == NULL) {
+    if (unlikely (comment_copy == NULL)) {
 	status = _cairo_surface_set_error (surface, CAIRO_STATUS_NO_MEMORY);
 	return;
     }
@@ -1733,7 +1733,7 @@ _string_array_stream_create (cairo_output_stream_t *output)
     string_array_stream_t *stream;
 
     stream = malloc (sizeof (string_array_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -1760,7 +1760,7 @@ _base85_array_stream_create (cairo_output_stream_t *output)
     string_array_stream_t *stream;
 
     stream = malloc (sizeof (string_array_stream_t));
-    if (stream == NULL) {
+    if (unlikely (stream == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
@@ -1940,7 +1940,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
 	data_size = image->height * image->width * 3;
     }
     data = malloc (data_size);
-    if (data == NULL) {
+    if (unlikely (data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto bail1;
     }
@@ -1989,7 +1989,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
      * instead. */
     data_compressed_size = data_size;
     data_compressed = _cairo_lzw_compress (data, &data_compressed_size);
-    if (data_compressed == NULL) {
+    if (unlikely (data_compressed == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto bail2;
     }
@@ -2749,7 +2749,7 @@ _cairo_ps_surface_emit_pattern_stops (cairo_ps_surface_t       *surface,
     unsigned int i, n_stops;
 
     allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_ps_color_stop_t));
-    if (allstops == NULL)
+    if (unlikely (allstops == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     stops = &allstops[1];
diff --git a/src/cairo-region.c b/src/cairo-region.c
index 146ae60..53a359b 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -64,7 +64,7 @@ _cairo_region_init_boxes (cairo_region_t *region,
 
     if (count > ARRAY_LENGTH (stack_pboxes)) {
 	pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t));
-	if (pboxes == NULL)
+	if (unlikely (pboxes == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index a1b4c22..c802c31 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -163,7 +163,7 @@ _cairo_sub_font_glyph_create (unsigned long	scaled_font_glyph_index,
     cairo_sub_font_glyph_t *sub_font_glyph;
 
     sub_font_glyph = malloc (sizeof (cairo_sub_font_glyph_t));
-    if (sub_font_glyph == NULL) {
+    if (unlikely (sub_font_glyph == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
@@ -267,7 +267,7 @@ _cairo_sub_font_create (cairo_scaled_font_subsets_t	*parent,
     cairo_scaled_font_subsets_glyph_t subset_glyph;
 
     sub_font = malloc (sizeof (cairo_sub_font_t));
-    if (sub_font == NULL)
+    if (unlikely (sub_font == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     sub_font->is_scaled = is_scaled;
@@ -284,7 +284,7 @@ _cairo_sub_font_create (cairo_scaled_font_subsets_t	*parent,
     sub_font->max_glyphs_per_subset = max_glyphs_per_subset;
 
     sub_font->sub_font_glyphs = _cairo_hash_table_create (_cairo_sub_font_glyphs_equal);
-    if (sub_font->sub_font_glyphs == NULL) {
+    if (unlikely (sub_font->sub_font_glyphs == NULL)) {
 	free (sub_font);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
@@ -360,7 +360,7 @@ _cairo_sub_font_glyph_lookup_unicode (cairo_sub_font_glyph_t *sub_font_glyph,
 	len = _cairo_ucs4_to_utf8 (unicode, buf);
 	if (len > 0) {
 	    sub_font_glyph->utf8 = malloc (len + 1);
-	    if (sub_font_glyph->utf8 == NULL)
+	    if (unlikely (sub_font_glyph->utf8 == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	    memcpy (sub_font_glyph->utf8, buf, len);
@@ -489,7 +489,7 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
                                                        scaled_glyph->metrics.y_advance);
 	_cairo_scaled_font_thaw_cache (sub_font->scaled_font);
 
-	if (sub_font_glyph == NULL)
+	if (unlikely (sub_font_glyph == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	status = _cairo_sub_font_glyph_lookup_unicode (sub_font_glyph,
@@ -596,8 +596,8 @@ _cairo_scaled_font_subsets_create_internal (cairo_subsets_type_t type)
 {
     cairo_scaled_font_subsets_t *subsets;
 
-    subsets = malloc (sizeof (cairo_scaled_font_subsets_t)); 
-    if (subsets == NULL) {
+    subsets = malloc (sizeof (cairo_scaled_font_subsets_t));
+    if (unlikely (subsets == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
@@ -744,7 +744,7 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
                                                       &identity,
                                                       &identity,
                                                       &font_options);
-	    if (unscaled_font->status)
+	    if (unlikely (unscaled_font->status))
 		return unscaled_font->status;
 
             subset_glyph->is_scaled = FALSE;
@@ -866,7 +866,7 @@ _cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t
 
     collection.glyphs = _cairo_malloc_ab (collection.glyphs_size, sizeof(unsigned long));
     collection.utf8 = _cairo_malloc_ab (collection.glyphs_size, sizeof(char *));
-    if (collection.glyphs == NULL || collection.utf8 == NULL) {
+    if (unlikely (collection.glyphs == NULL || collection.utf8 == NULL)) {
 	if (collection.glyphs != NULL)
 	    free (collection.glyphs);
 	if (collection.utf8 != NULL)
@@ -957,7 +957,7 @@ static cairo_status_t
 create_string_entry (char *s, cairo_string_entry_t **entry)
 {
     *entry = malloc (sizeof (cairo_string_entry_t));
-    if (*entry == NULL)
+    if (unlikely (*entry == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     _cairo_string_init_key (*entry, s);
@@ -985,11 +985,11 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
     names = _cairo_hash_table_create (_cairo_string_equal);
-    if (names == NULL)
+    if (unlikely (names == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     subset->glyph_names = calloc (subset->num_glyphs, sizeof (char *));
-    if (subset->glyph_names == NULL) {
+    if (unlikely (subset->glyph_names == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP_HASH;
     }
@@ -997,7 +997,7 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
     i = 0;
     if (! _cairo_font_face_is_user (subset->scaled_font->font_face)) {
 	subset->glyph_names[0] = strdup (".notdef");
-	if (subset->glyph_names[0] == NULL) {
+	if (unlikely (subset->glyph_names[0] == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP_HASH;
 	}
@@ -1037,7 +1037,7 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	    free (utf16);
 
 	subset->glyph_names[i] = strdup (buf);
-	if (subset->glyph_names[i] == NULL) {
+	if (unlikely (subset->glyph_names[i] == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP_HASH;
 	}
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 76572a5..ca86f51 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -321,14 +321,14 @@ _cairo_scaled_font_map_lock (void)
 
     if (cairo_scaled_font_map == NULL) {
 	cairo_scaled_font_map = malloc (sizeof (cairo_scaled_font_map_t));
-	if (cairo_scaled_font_map == NULL)
+	if (unlikely (cairo_scaled_font_map == NULL))
 	    goto CLEANUP_MUTEX_LOCK;
 
 	cairo_scaled_font_map->mru_scaled_font = NULL;
 	cairo_scaled_font_map->hash_table =
 	    _cairo_hash_table_create (_cairo_scaled_font_keys_equal);
 
-	if (cairo_scaled_font_map->hash_table == NULL)
+	if (unlikely (cairo_scaled_font_map->hash_table == NULL))
 	    goto CLEANUP_SCALED_FONT_MAP;
 
 	cairo_scaled_font_map->num_holdovers = 0;
@@ -360,7 +360,7 @@ _cairo_scaled_font_map_destroy (void)
     CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex);
 
     font_map = cairo_scaled_font_map;
-    if (font_map == NULL) {
+    if (unlikely (font_map == NULL)) {
         goto CLEANUP_MUTEX_LOCK;
     }
 
@@ -429,7 +429,7 @@ _cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t
 	return status;
 
     placeholder_scaled_font = malloc (sizeof (cairo_scaled_font_t));
-    if (placeholder_scaled_font == NULL)
+    if (unlikely (placeholder_scaled_font == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     /* full initialization is wasteful, but who cares... */
@@ -638,7 +638,7 @@ _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
     scaled_font->glyphs = _cairo_cache_create (_cairo_scaled_glyph_keys_equal,
 					       _cairo_scaled_glyph_destroy,
 					       MAX_GLYPHS_CACHED_PER_FONT);
-    if (scaled_font->glyphs == NULL)
+    if (unlikely (scaled_font->glyphs == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     CAIRO_REFERENCE_COUNT_INIT (&scaled_font->ref_count, 1);
@@ -797,7 +797,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	impl_face = font_face;
 
     font_map = _cairo_scaled_font_map_lock ();
-    if (font_map == NULL)
+    if (unlikely (font_map == NULL))
 	return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_scaled_font_init_key (&key, impl_face,
@@ -935,9 +935,9 @@ _cairo_scaled_font_create_in_error (cairo_status_t status)
 
     CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex);
     scaled_font = _cairo_scaled_font_nil_objects[status];
-    if (scaled_font == NULL) {
+    if (unlikely (scaled_font == NULL)) {
 	scaled_font = malloc (sizeof (cairo_scaled_font_t));
-	if (scaled_font == NULL) {
+	if (unlikely (scaled_font == NULL)) {
 	    CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex);
 	    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	    return (cairo_scaled_font_t *) &_cairo_scaled_font_nil;
@@ -1642,7 +1642,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
 
     if (*num_glyphs < num_chars) {
 	*glyphs = cairo_glyph_allocate (num_chars);
-	if (*glyphs == NULL) {
+	if (unlikely (*glyphs == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto DONE;
 	}
@@ -1652,7 +1652,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
     if (clusters) {
 	if (*num_clusters < num_chars) {
 	    *clusters = cairo_text_cluster_allocate (num_chars);
-	    if (*clusters == NULL) {
+	    if (unlikely (*clusters == NULL)) {
 		status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		goto DONE;
 	    }
@@ -1864,10 +1864,9 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
 	    mask_format = glyph_surface->format;
 	    mask = cairo_image_surface_create (mask_format,
 					       width, height);
-	    if (mask->status) {
-		status = mask->status;
+	    status = mask->status;
+	    if (unlikely (status))
 		goto CLEANUP_MASK;
-	    }
 	}
 
 	/* If we have glyphs of different formats, we "upgrade" the mask
@@ -2157,7 +2156,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
 		goto BAIL;
 
 	    glyph_path = _cairo_path_fixed_create ();
-	    if (glyph_path == NULL) {
+	    if (unlikely (glyph_path == NULL)) {
 		status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		goto BAIL;
 	    }
@@ -2361,7 +2360,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 	 * On miss, create glyph and insert into cache
 	 */
 	scaled_glyph = malloc (sizeof (cairo_scaled_glyph_t));
-	if (scaled_glyph == NULL) {
+	if (unlikely (scaled_glyph == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP;
 	}
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index fc3164d..77a9e5f 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -186,7 +186,7 @@ _bitmap_next_id (struct _bitmap *b,
     } while (b != NULL);
 
     bb = malloc (sizeof (struct _bitmap));
-    if (bb == NULL)
+    if (unlikely (bb == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     *prev = bb;
@@ -852,7 +852,7 @@ _write_image_surface (cairo_output_stream_t *output,
 #else
     if (stride > ARRAY_LENGTH (row_stack)) {
 	rowdata = malloc (stride);
-	if (rowdata == NULL)
+	if (unlikely (rowdata == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else
 	rowdata = row_stack;
@@ -1832,7 +1832,7 @@ _emit_type42_font (cairo_script_surface_t *surface,
 	return status;
 
     buf = malloc (size);
-    if (buf == NULL)
+    if (unlikely (buf == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font, 0, 0, buf, NULL);
@@ -1882,7 +1882,7 @@ _emit_scaled_font_init (cairo_script_surface_t *surface,
     cairo_status_t status;
 
     font_private = malloc (sizeof (cairo_script_surface_font_private_t));
-    if (font_private == NULL)
+    if (unlikely (font_private == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font_private->ctx = surface->ctx;
@@ -2466,7 +2466,7 @@ _cairo_script_vmcontext_create (cairo_output_stream_t *stream)
     cairo_script_vmcontext_t *ctx;
 
     ctx = malloc (sizeof (cairo_script_vmcontext_t));
-    if (ctx == NULL)
+    if (unlikely (ctx == NULL))
 	return NULL;
 
     memset (ctx, 0, sizeof (cairo_script_vmcontext_t));
@@ -2500,11 +2500,11 @@ _cairo_script_surface_create_internal (cairo_script_vmcontext_t *ctx,
 {
     cairo_script_surface_t *surface;
 
-    if (ctx == NULL)
+    if (unlikely (ctx == NULL))
 	return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     surface = malloc (sizeof (cairo_script_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&surface->base,
diff --git a/src/cairo-sdl-surface.c b/src/cairo-sdl-surface.c
index 800ad83..d98566d 100644
--- a/src/cairo-sdl-surface.c
+++ b/src/cairo-sdl-surface.c
@@ -52,7 +52,7 @@ _cairo_sdl_surface_create_internal (SDL_Surface *sdl,
     cairo_sdl_surface_t *surface;
 
     surface = malloc (sizeof (cairo_sdl_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&surface->base,
diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c
index 02e1556..d03a6bf 100644
--- a/src/cairo-skiplist.c
+++ b/src/cairo-skiplist.c
@@ -183,7 +183,7 @@ _cairo_skip_list_insert (cairo_skip_list_t *list, void *data, int unique)
     }
 
     data_and_elt = alloc_node_for_level (list, level);
-    if (data_and_elt == NULL) {
+    if (unlikely (data_and_elt == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
diff --git a/src/cairo-stroke-style.c b/src/cairo-stroke-style.c
index 3bc234e..edc4f88 100644
--- a/src/cairo-stroke-style.c
+++ b/src/cairo-stroke-style.c
@@ -63,7 +63,7 @@ _cairo_stroke_style_init_copy (cairo_stroke_style_t *style,
 	style->dash = NULL;
     } else {
 	style->dash = _cairo_malloc_ab (style->num_dashes, sizeof (double));
-	if (style->dash == NULL)
+	if (unlikely (style->dash == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	memcpy (style->dash, other->dash,
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index bb80538..8e6e268 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -1183,7 +1183,7 @@ _cairo_surface_fallback_fill_rectangles (cairo_surface_t         *surface,
 
     if (state.image_rect.x != 0 || state.image_rect.y != 0) {
 	offset_rects = _cairo_malloc_ab (num_rects, sizeof (cairo_rectangle_int_t));
-	if (offset_rects == NULL) {
+	if (unlikely (offset_rects == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto DONE;
 	}
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index a6c97f2..dff8d9f 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -237,7 +237,7 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other,
     }
 
     /* If any error occurred, then return the nil surface we received. */
-    if (surface->status)
+    if (unlikely (surface->status))
 	return surface;
 
     if (other->has_font_options || other->backend != surface->backend) {
@@ -677,7 +677,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 
     if (data != NULL) {
 	mime_data = malloc (sizeof (cairo_mime_data_t));
-	if (mime_data == NULL)
+	if (unlikely (mime_data == NULL))
 	    return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY));
 
 	CAIRO_REFERENCE_COUNT_INIT (&mime_data->ref_count, 1);
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 35e256f..8b66662 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -347,7 +347,7 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t	*document,
     cairo_status_t status, status_ignored;
 
     surface = malloc (sizeof (cairo_svg_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&surface->base, &cairo_svg_surface_backend,
@@ -482,7 +482,7 @@ _cairo_svg_surface_copy_page (void *abstract_surface)
     cairo_svg_page_t *page;
 
     page = _cairo_svg_surface_store_page (surface);
-    if (page == NULL)
+    if (unlikely (page == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     _cairo_memory_stream_copy (page->xml_node, surface->xml_node);
@@ -496,7 +496,7 @@ _cairo_svg_surface_show_page (void *abstract_surface)
 {
     cairo_svg_surface_t *surface = abstract_surface;
 
-    if (_cairo_svg_surface_store_page (surface) == NULL)
+    if (unlikely (_cairo_svg_surface_store_page (surface) == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
@@ -1268,7 +1268,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document,
     page_set = &svg_surface->page_set;
 
     if (_cairo_memory_stream_length (contents) > 0) {
-	if (_cairo_svg_surface_store_page (svg_surface) == NULL) {
+	if (unlikely (_cairo_svg_surface_store_page (svg_surface) == NULL)) {
 	    cairo_surface_destroy (paginated_surface);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
@@ -1449,7 +1449,7 @@ _cairo_svg_surface_emit_pattern_stops (cairo_output_stream_t          *output,
     if (emulate_reflect || reverse_stops) {
 	n_stops = emulate_reflect ? pattern->n_stops * 2 - 2: pattern->n_stops;
 	stops = _cairo_malloc_ab (n_stops, sizeof (cairo_gradient_stop_t));
-	if (stops == NULL)
+	if (unlikely (stops == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	for (i = 0; i < pattern->n_stops; i++) {
@@ -2458,12 +2458,12 @@ _cairo_svg_document_create (cairo_output_stream_t	 *output_stream,
 	return output_stream->status;
 
     document = malloc (sizeof (cairo_svg_document_t));
-    if (document == NULL)
+    if (unlikely (document == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     /* The use of defs for font glyphs imposes no per-subset limit. */
     document->font_subsets = _cairo_scaled_font_subsets_create_scaled ();
-    if (document->font_subsets == NULL) {
+    if (unlikely (document->font_subsets == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP_DOCUMENT;
     }
@@ -2607,7 +2607,7 @@ _cairo_svg_document_finish (cairo_svg_document_t *document)
 	surface = (cairo_svg_surface_t *) _cairo_paginated_surface_get_target (document->owner);
 	if (surface->xml_node != NULL &&
 		_cairo_memory_stream_length (surface->xml_node) > 0) {
-	    if (_cairo_svg_surface_store_page (surface) == NULL) {
+	    if (unlikely (_cairo_svg_surface_store_page (surface) == NULL)) {
 		if (status == CAIRO_STATUS_SUCCESS)
 		    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index a871702..0afdce2 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -140,7 +140,7 @@ _cairo_traps_grow (cairo_traps_t *traps)
 	                               new_size, sizeof (cairo_trapezoid_t));
     }
 
-    if (new_traps == NULL) {
+    if (unlikely (new_traps == NULL)) {
 	traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return FALSE;
     }
@@ -635,7 +635,7 @@ _cairo_traps_extract_region (const cairo_traps_t  *traps,
     if (traps->num_traps > ARRAY_LENGTH (stack_boxes)) {
 	boxes = _cairo_malloc_ab (traps->num_traps, sizeof (cairo_box_int_t));
 
-	if (boxes == NULL)
+	if (unlikely (boxes == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index b3a4815..4662eaa 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -173,8 +173,8 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     if (unlikely (status))
 	return status;
 
-    name = malloc(size);
-    if (name == NULL)
+    name = malloc (size);
+    if (unlikely (name == NULL))
         return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
@@ -185,7 +185,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 	goto fail0;
 
     font = malloc (sizeof (cairo_truetype_font_t));
-    if (font == NULL) {
+    if (unlikely (font == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail0;
     }
@@ -202,13 +202,13 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 	goto fail1;
 
     font->glyphs = calloc (font->num_glyphs_in_face + 1, sizeof (subset_glyph_t));
-    if (font->glyphs == NULL) {
+    if (unlikely (font->glyphs == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
 
     font->parent_to_subset = calloc (font->num_glyphs_in_face, sizeof (int));
-    if (font->parent_to_subset == NULL) {
+    if (unlikely (font->parent_to_subset == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -252,7 +252,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 
     if (font->base.base_font == NULL) {
         font->base.base_font = malloc (30);
-        if (font->base.base_font == NULL) {
+        if (unlikely (font->base.base_font == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
             goto fail3;
 	}
@@ -270,7 +270,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->base.base_font[i] = '\0';
 
     font->base.widths = calloc (font->num_glyphs_in_face, sizeof (int));
-    if (font->base.widths == NULL) {
+    if (unlikely (font->base.widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail4;
     }
@@ -577,14 +577,14 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
 						 (unsigned char*) &header, &size);
     if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
-    
+
     if (be16_to_cpu (header.index_to_loc_format) == 0)
 	size = sizeof (int16_t) * (font->num_glyphs_in_face + 1);
     else
 	size = sizeof (int32_t) * (font->num_glyphs_in_face + 1);
 
     u.bytes = malloc (size);
-    if (u.bytes == NULL)
+    if (unlikely (u.bytes == NULL))
 	return _cairo_truetype_font_set_error (font, CAIRO_STATUS_NO_MEMORY);
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
@@ -1098,7 +1098,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 	goto fail1;
 
     truetype_subset->base_font = strdup (font->base.base_font);
-    if (truetype_subset->base_font == NULL) {
+    if (unlikely (truetype_subset->base_font == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
@@ -1108,7 +1108,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
      * font_subset->num_glyphs are omitted. */
     truetype_subset->widths = calloc (sizeof (double),
                                       font->scaled_font_subset->num_glyphs);
-    if (truetype_subset->widths == NULL) {
+    if (unlikely (truetype_subset->widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -1124,7 +1124,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 
     if (length) {
 	truetype_subset->data = malloc (length);
-	if (truetype_subset->data == NULL) {
+	if (unlikely (truetype_subset->data == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto fail3;
 	}
@@ -1137,7 +1137,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
     if (num_strings) {
 	offsets_length = num_strings * sizeof (unsigned long);
 	truetype_subset->string_offsets = malloc (offsets_length);
-	if (truetype_subset->string_offsets == NULL) {
+	if (unlikely (truetype_subset->string_offsets == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto fail4;
 	}
@@ -1209,7 +1209,7 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
 
     size = be16_to_cpu (map->length);
     map = malloc (size);
-    if (map == NULL)
+    if (unlikely (map == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font,
@@ -1306,7 +1306,7 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
     num_tables = be16_to_cpu (cmap->num_tables);
     size = 4 + num_tables*sizeof(tt_cmap_index_t);
     cmap = _cairo_malloc_ab_plus_c (num_tables, sizeof (tt_cmap_index_t), 4);
-    if (cmap == NULL)
+    if (unlikely (cmap == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font,
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index d54215d..91c0054 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -85,12 +85,11 @@ cairo_type1_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     cairo_status_t status;
 
     font = calloc (1, sizeof (cairo_type1_font_t));
-    if (font == NULL)
+    if (unlikely (font == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-    font->widths = calloc (scaled_font_subset->num_glyphs,
-                           sizeof (int));
-    if (font->widths == NULL) {
+    font->widths = calloc (scaled_font_subset->num_glyphs, sizeof (int));
+    if (unlikely (font->widths == NULL)) {
 	free (font);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
@@ -722,13 +721,13 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t	*type1_subset,
 	goto fail1;
 
     type1_subset->base_font = strdup (name);
-    if (type1_subset->base_font == NULL) {
+    if (unlikely (type1_subset->base_font == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail1;
     }
 
     type1_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
-    if (type1_subset->widths == NULL) {
+    if (unlikely (type1_subset->widths == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail2;
     }
@@ -745,7 +744,7 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t	*type1_subset,
     length = font->header_size + font->data_size +
 	font->trailer_size;
     type1_subset->data = malloc (length);
-    if (type1_subset->data == NULL) {
+    if (unlikely (type1_subset->data == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail3;
     }
@@ -822,7 +821,7 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
     _cairo_array_init (&type2_subset->charstrings, sizeof (cairo_array_t));
 
     type2_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
-    if (type2_subset->widths == NULL) {
+    if (unlikely (type2_subset->widths == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         goto fail1;
     }
diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index a62a261..fe74dc6 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -126,7 +126,7 @@ _cairo_type1_font_subset_init (cairo_type1_font_subset_t  *font,
     ft_unscaled_font = (cairo_ft_unscaled_font_t *) unscaled_font;
 
     face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
-    if (face == NULL)
+    if (unlikely (face == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     if (FT_Get_PS_Font_Info(face, &font_info) != 0) {
@@ -154,7 +154,7 @@ _cairo_type1_font_subset_init (cairo_type1_font_subset_t  *font,
 
     if (face->family_name) {
 	font->base.base_font = strdup (face->family_name);
-	if (font->base.base_font == NULL) {
+	if (unlikely (font->base.base_font == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto fail2;
 	}
@@ -167,7 +167,7 @@ _cairo_type1_font_subset_init (cairo_type1_font_subset_t  *font,
     }
 
     font->glyphs = calloc (face->num_glyphs, sizeof font->glyphs[0]);
-    if (font->glyphs == NULL) {
+    if (unlikely (font->glyphs == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail3;
     }
@@ -467,7 +467,7 @@ cairo_type1_font_subset_decrypt_eexec_segment (cairo_type1_font_subset_t *font)
     end = (unsigned char *) in + font->eexec_segment_size;
 
     font->cleartext = malloc (font->eexec_segment_size);
-    if (font->cleartext == NULL)
+    if (unlikely (font->cleartext == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     out = font->cleartext;
@@ -573,7 +573,7 @@ cairo_type1_font_subset_get_glyph_names_and_widths (cairo_type1_font_subset_t *f
 	}
 
 	font->glyphs[i].name = strdup (buffer);
-	if (font->glyphs[i].name == NULL)
+	if (unlikely (font->glyphs[i].name == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
@@ -838,7 +838,7 @@ cairo_type1_font_subset_look_for_seac(cairo_type1_font_subset_t *font,
     int command;
 
     charstring = malloc (encrypted_charstring_length);
-    if (charstring == NULL)
+    if (unlikely (charstring == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     cairo_type1_font_subset_decrypt_charstring ((const unsigned char *)
@@ -1210,12 +1210,12 @@ cairo_type1_font_subset_generate (void       *abstract_font,
 
     ft_unscaled_font = (cairo_ft_unscaled_font_t *) font->base.unscaled_font;
     font->face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
-    if (font->face == NULL)
+    if (unlikely (font->face == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->type1_length = font->face->stream->size;
     font->type1_data = malloc (font->type1_length);
-    if (font->type1_data == NULL) {
+    if (unlikely (font->type1_data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail;
     }
@@ -1325,11 +1325,11 @@ _cairo_type1_subset_init (cairo_type1_subset_t		*type1_subset,
                  scaled_font_subset->font_id, scaled_font_subset->subset_id);
 	type1_subset->base_font = strdup (buf);
     }
-    if (type1_subset->base_font == NULL)
+    if (unlikely (type1_subset->base_font == NULL))
 	goto fail1;
 
     type1_subset->widths = calloc (sizeof (int), font.num_glyphs);
-    if (type1_subset->widths == NULL)
+    if (unlikely (type1_subset->widths == NULL))
 	goto fail2;
     for (i = 0; i < font.base.num_glyphs; i++) {
 	if (font.glyphs[i].subset_index < 0)
@@ -1349,7 +1349,7 @@ _cairo_type1_subset_init (cairo_type1_subset_t		*type1_subset,
 	     font.base.data_size +
 	     font.base.trailer_size;
     type1_subset->data = malloc (length);
-    if (type1_subset->data == NULL)
+    if (unlikely (type1_subset->data == NULL))
 	goto fail3;
 
     memcpy (type1_subset->data,
diff --git a/src/cairo-type3-glyph-surface.c b/src/cairo-type3-glyph-surface.c
index 7106040..ebc78dd 100644
--- a/src/cairo-type3-glyph-surface.c
+++ b/src/cairo-type3-glyph-surface.c
@@ -55,7 +55,7 @@ _cairo_type3_glyph_surface_create (cairo_scaled_font_t	 		 *scaled_font,
     cairo_matrix_t invert_y_axis;
 
     surface = malloc (sizeof (cairo_type3_glyph_surface_t));
-    if (surface == NULL)
+    if (unlikely (surface == NULL))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     _cairo_surface_init (&surface->base, &cairo_type3_glyph_surface_backend,
diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 5e2077f..6670b53 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -420,7 +420,7 @@ _cairo_user_font_face_scaled_font_create (void                        *abstract_
     font_face->immutable = TRUE;
 
     user_scaled_font = malloc (sizeof (cairo_user_scaled_font_t));
-    if (user_scaled_font == NULL)
+    if (unlikely (user_scaled_font == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_scaled_font_init (&user_scaled_font->base,
diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index 2823e5d..e85174b 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -248,7 +248,7 @@ _cairo_xlib_display_get (Display *dpy,
     }
 
     display = malloc (sizeof (cairo_xlib_display_t));
-    if (display == NULL) {
+    if (unlikely (display == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNLOCK;
     }
@@ -262,7 +262,7 @@ _cairo_xlib_display_get (Display *dpy,
     XRenderQueryVersion (dpy, &render_major, &render_minor);
 
     codes = XAddExtension (dpy);
-    if (codes == NULL) {
+    if (unlikely (codes == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	free (display);
 	display = NULL;
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 1878f8e..3b1ae2e 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -352,7 +352,7 @@ _cairo_xlib_screen_info_get (cairo_xlib_display_t *display,
 	info = _cairo_xlib_screen_info_reference (info);
     } else {
 	info = malloc (sizeof (cairo_xlib_screen_info_t));
-	if (info == NULL)
+	if (unlikely (info == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	CAIRO_REFERENCE_COUNT_INIT (&info->ref_count, 2); /* Add one for display cache */
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 75d4de3..0e91513 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -147,9 +147,8 @@ _cairo_xlib_surface_create_similar_with_format (void	       *abstract_src,
     if (! CAIRO_SURFACE_RENDER_HAS_COMPOSITE (src))
 	return NULL;
 
-    xrender_format = _cairo_xlib_display_get_xrender_format (
-	                                              src->display,
-						      format);
+    xrender_format = _cairo_xlib_display_get_xrender_format (src->display,
+							     format);
     if (xrender_format == NULL)
 	return NULL;
 
@@ -910,7 +909,7 @@ _cairo_xlib_surface_ensure_gc (cairo_xlib_surface_t *surface)
 	    gcv.graphics_exposures = False;
 	    surface->gc = XCreateGC (surface->dpy, surface->drawable,
 				     GCGraphicsExposures, &gcv);
-	    if (!surface->gc)
+	    if (unlikely (surface->gc == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
     }
@@ -990,7 +989,7 @@ _draw_image_surface (cairo_xlib_surface_t   *surface,
 					     ximage.bits_per_pixel);
 	ximage.bytes_per_line = stride;
 	ximage.data = _cairo_malloc_ab (stride, ximage.height);
-	if (ximage.data == NULL)
+	if (unlikely (ximage.data == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
 	own_data = TRUE;
@@ -1964,7 +1963,7 @@ _cairo_xlib_surface_fill_rectangles (void		     *abstract_surface,
 
 	if (num_rects > ARRAY_LENGTH (static_xrects)) {
 	    xrects = _cairo_malloc_ab (num_rects, sizeof (XRectangle));
-	    if (xrects == NULL)
+	    if (unlikely (xrects == NULL))
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
@@ -2225,7 +2224,7 @@ _cairo_xlib_surface_composite_trapezoids (cairo_operator_t	op,
 
         if (num_traps > ARRAY_LENGTH (xtraps_stack)) {
             xtraps = _cairo_malloc_ab (num_traps, sizeof (XTrapezoid));
-            if (xtraps == NULL) {
+            if (unlikely (xtraps == NULL)) {
                 status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
                 goto BAIL;
             }
@@ -2317,7 +2316,7 @@ _cairo_xlib_surface_set_clip_region (void           *abstract_surface,
 
 	if (n_boxes > ARRAY_LENGTH (surface->embedded_clip_rects)) {
 	    rects = _cairo_malloc_ab (n_boxes, sizeof (XRectangle));
-	    if (rects == NULL) {
+	    if (unlikely (rects == NULL)) {
                 _cairo_region_boxes_fini (&bounded, boxes);
 		_cairo_region_fini (&bound);
 		_cairo_region_fini (&bounded);
@@ -2574,7 +2573,7 @@ _cairo_xlib_surface_create_internal (Display		       *dpy,
     }
 
     surface = malloc (sizeof (cairo_xlib_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	_cairo_xlib_screen_info_destroy (screen_info);
 	_cairo_xlib_display_destroy (display);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
@@ -3168,7 +3167,7 @@ _cairo_xlib_surface_font_init (Display		    *dpy,
     int i;
 
     font_private = malloc (sizeof (cairo_xlib_surface_font_private_t));
-    if (font_private == NULL)
+    if (unlikely (font_private == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font_private->scaled_font = scaled_font;
@@ -3297,7 +3296,7 @@ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
 
 	if (to_free == NULL) {
 	    to_free = malloc (sizeof (cairo_xlib_font_glyphset_free_glyphs_t));
-	    if (to_free == NULL) {
+	    if (unlikely (to_free == NULL)) {
 		_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 		return; /* XXX cannot propagate failure */
 	    }
@@ -3579,7 +3578,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 	    unsigned char   *new, *n;
 
 	    new = malloc (c);
-	    if (new == NULL) {
+	    if (unlikely (new == NULL)) {
 		status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		goto BAIL;
 	    }
@@ -3723,7 +3722,7 @@ _emit_glyphs_chunk (cairo_xlib_surface_t *dst,
       elts = stack_elts;
     } else {
       elts = _cairo_malloc_ab (num_elts, sizeof (XGlyphElt8));
-      if (elts == NULL)
+      if (unlikely (elts == NULL))
 	  return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
diff --git a/src/cairo-xlib-visual.c b/src/cairo-xlib-visual.c
index f6eb1ee..7dbe86c 100644
--- a/src/cairo-xlib-visual.c
+++ b/src/cairo-xlib-visual.c
@@ -78,7 +78,7 @@ _cairo_xlib_visual_info_create (Display *dpy,
 	ramp_index_to_short[i] = (0xffff * i + ((RAMP_SIZE-1)>>1)) / (RAMP_SIZE-1);
 
     info = malloc (sizeof (cairo_xlib_visual_info_t));
-    if (info == NULL)
+    if (unlikely (info == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     info->visualid = visualid;
diff --git a/src/cairo.c b/src/cairo.c
index 924f7ca..75674f9 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -152,7 +152,7 @@ cairo_create (cairo_surface_t *target)
 	return (cairo_t *) &_cairo_nil;
 
     cr = malloc (sizeof (cairo_t));
-    if (cr == NULL) {
+    if (unlikely (cr == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_t *) &_cairo_nil;
     }
@@ -2529,7 +2529,7 @@ _cairo_rectangle_list_create_in_error (cairo_status_t status)
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 
     list = malloc (sizeof (cairo_rectangle_list_t));
-    if (list == NULL) {
+    if (unlikely (list == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
     }
diff --git a/src/test-fallback-surface.c b/src/test-fallback-surface.c
index 883941d..d20e7c9 100644
--- a/src/test-fallback-surface.c
+++ b/src/test-fallback-surface.c
@@ -79,7 +79,7 @@ _cairo_test_fallback_surface_create (cairo_content_t	content,
 	return backing;
 
     surface = malloc (sizeof (test_fallback_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	cairo_surface_destroy (backing);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
     }
diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c
index 71700bd..6ac1803 100644
--- a/src/test-meta-surface.c
+++ b/src/test-meta-surface.c
@@ -77,7 +77,7 @@ _cairo_test_meta_surface_create (cairo_content_t	content,
     cairo_status_t status;
 
     surface = malloc (sizeof (test_meta_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
diff --git a/src/test-paginated-surface.c b/src/test-paginated-surface.c
index cfb87f3..58d5b0a 100644
--- a/src/test-paginated-surface.c
+++ b/src/test-paginated-surface.c
@@ -80,7 +80,7 @@ _cairo_test_paginated_surface_create_for_data (unsigned char		*data,
 	return target;
 
     surface = malloc (sizeof (test_paginated_surface_t));
-    if (surface == NULL) {
+    if (unlikely (surface == NULL)) {
 	cairo_surface_destroy (target);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
     }
commit d1801c23fae3777c7c59e084894a3410f7a1f932
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 18 15:38:37 2008 +0000

    Mark if(status) as being unlikely.
    
    The error paths should be hit very rarely during normal operation, so mark
    them as being unlikely so gcc may emit better code.

diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index 3109dee..9fb19a8 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -337,7 +337,7 @@ _cairo_analysis_surface_paint (void			*abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -407,7 +407,7 @@ _cairo_analysis_surface_mask (void		*abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -417,7 +417,7 @@ _cairo_analysis_surface_mask (void		*abstract_surface,
 	cairo_rectangle_int_t mask_extents;
 
 	status = _cairo_pattern_get_extents (mask, &mask_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &mask_extents);
@@ -469,7 +469,7 @@ _cairo_analysis_surface_stroke (void			*abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -489,7 +489,7 @@ _cairo_analysis_surface_stroke (void			*abstract_surface,
 						    ctm, ctm_inverse,
 						    tolerance,
 						    &traps);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_traps_fini (&traps);
 	    return status;
 	}
@@ -541,7 +541,7 @@ _cairo_analysis_surface_fill (void			*abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -560,7 +560,7 @@ _cairo_analysis_surface_fill (void			*abstract_surface,
 						  fill_rule,
 						  tolerance,
 						  &traps);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_traps_fini (&traps);
 	    return status;
 	}
@@ -622,7 +622,7 @@ _cairo_analysis_surface_show_glyphs (void		  *abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -635,7 +635,7 @@ _cairo_analysis_surface_show_glyphs (void		  *abstract_surface,
 							  glyphs,
 							  num_glyphs,
 							  &glyph_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &glyph_extents);
@@ -708,7 +708,7 @@ _cairo_analysis_surface_show_text_glyphs (void			    *abstract_surface,
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &source_extents);
@@ -721,7 +721,7 @@ _cairo_analysis_surface_show_text_glyphs (void			    *abstract_surface,
 							  glyphs,
 							  num_glyphs,
 							  &glyph_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	is_empty = _cairo_rectangle_intersect (&extents, &glyph_extents);
@@ -780,7 +780,7 @@ _cairo_analysis_surface_create (cairo_surface_t		*target,
     cairo_status_t status;
 
     status = target->status;
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_create_in_error (status);
 
     surface = malloc (sizeof (cairo_analysis_surface_t));
diff --git a/src/cairo-array.c b/src/cairo-array.c
index f38cfe3..ef50684 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -279,7 +279,7 @@ _cairo_array_append_multiple (cairo_array_t	*array,
     assert (! array->is_snapshot);
 
     status = _cairo_array_allocate (array, num_elements, &dest);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     memcpy (dest, elements, num_elements * array->element_size);
@@ -310,7 +310,7 @@ _cairo_array_allocate (cairo_array_t	 *array,
     assert (! array->is_snapshot);
 
     status = _cairo_array_grow_by (array, num_elements);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     assert (array->num_elements + num_elements <= array->size);
@@ -489,7 +489,7 @@ _cairo_user_data_array_set_data (cairo_user_data_array_t     *array,
     }
 
     status = _cairo_array_append (array, &new_slot);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index f5caba4..7317264 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -131,7 +131,7 @@ _cairo_cache_create (cairo_cache_keys_equal_func_t keys_equal,
     }
 
     status = _cairo_cache_init (cache, keys_equal, entry_destroy, max_size);
-    if (status) {
+    if (unlikely (status)) {
 	free (cache);
 	return NULL;
     }
@@ -293,7 +293,7 @@ _cairo_cache_insert (cairo_cache_t	 *cache,
 
     status = _cairo_hash_table_insert (cache->hash_table,
 				       (cairo_hash_entry_t *) entry);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cache->size += entry->size;
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 45be5d1..2d1fd8f 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -298,7 +298,7 @@ cff_index_read (cairo_array_t *index, unsigned char **ptr, unsigned char *end_pt
             element.is_copy = FALSE;
             element.data = data + start;
             status = _cairo_array_append (index, &element);
-            if (status)
+            if (unlikely (status))
                 return status;
             start = end;
         }
@@ -324,7 +324,7 @@ cff_index_write (cairo_array_t *index, cairo_array_t *output)
     num_elem = _cairo_array_num_elements (index);
     count = cpu_to_be16 ((uint16_t) num_elem);
     status = _cairo_array_append_multiple (output, &count, 2);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (num_elem == 0)
@@ -347,13 +347,13 @@ cff_index_write (cairo_array_t *index, cairo_array_t *output)
 
     buf[0] = (unsigned char) offset_size;
     status = _cairo_array_append (output, buf);
-    if (status)
+    if (unlikely (status))
         return status;
 
     offset = 1;
     encode_index_offset (buf, offset_size, offset);
     status = _cairo_array_append_multiple (output, buf, offset_size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     for (i = 0; i < num_elem; i++) {
@@ -361,7 +361,7 @@ cff_index_write (cairo_array_t *index, cairo_array_t *output)
         offset += element->length;
         encode_index_offset (buf, offset_size, offset);
         status = _cairo_array_append_multiple (output, buf, offset_size);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -370,7 +370,7 @@ cff_index_write (cairo_array_t *index, cairo_array_t *output)
         status = _cairo_array_append_multiple (output,
                                                element->data,
                                                element->length);
-        if (status)
+        if (unlikely (status))
             return status;
     }
     return CAIRO_STATUS_SUCCESS;
@@ -405,7 +405,7 @@ cff_index_append_copy (cairo_array_t *index,
     memcpy (element.data, object, element.length);
 
     status = _cairo_array_append (index, &element);
-    if (status) {
+    if (unlikely (status)) {
 	free (element.data);
 	return status;
     }
@@ -496,7 +496,7 @@ cff_dict_read (cairo_hash_table_t *dict, unsigned char *p, int dict_size)
         size = operand_length (p);
         if (size != 0) {
             status = _cairo_array_append_multiple (&operands, p, size);
-            if (status)
+            if (unlikely (status))
                 goto fail;
 
             p += size;
@@ -506,11 +506,11 @@ cff_dict_read (cairo_hash_table_t *dict, unsigned char *p, int dict_size)
                                           _cairo_array_index (&operands, 0),
                                           _cairo_array_num_elements (&operands),
 					  &op);
-            if (status)
+            if (unlikely (status))
                 goto fail;
 
             status = _cairo_hash_table_insert (dict, &op->base);
-            if (status)
+            if (unlikely (status))
                 goto fail;
 
             _cairo_array_truncate (&operands, 0);
@@ -577,11 +577,11 @@ cff_dict_set_operands (cairo_hash_table_t *dict,
     else
     {
         status = cff_dict_create_operator (operator, operand, size, &op);
-        if (status)
+        if (unlikely (status))
 	    return status;
 
 	status = _cairo_hash_table_insert (dict, &op->base);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -724,7 +724,7 @@ cairo_cff_font_read_private_dict (cairo_cff_font_t   *font,
     unsigned char *p;
 
     status = cff_dict_read (private_dict, ptr, size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     operand = cff_dict_get_operands (private_dict, LOCAL_SUB_OP, &i);
@@ -732,13 +732,13 @@ cairo_cff_font_read_private_dict (cairo_cff_font_t   *font,
         decode_integer (operand, &offset);
         p = ptr + offset;
         status = cff_index_read (local_sub_index, &p, font->data_end);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
         /* Use maximum sized encoding to reserve space for later modification. */
         end_buf = encode_integer_max (buf, 0);
         status = cff_dict_set_operands (private_dict, LOCAL_SUB_OP, buf, end_buf - buf);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -793,7 +793,7 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
 
     cff_index_init (&index);
     status = cff_index_read (&index, &ptr, font->data_end);
-    if (status)
+    if (unlikely (status))
         goto fail;
 
     font->num_fontdicts = _cairo_array_num_elements (&index);
@@ -818,12 +818,12 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
 
     for (i = 0; i < font->num_fontdicts; i++) {
         status = cff_dict_init (&font->fd_dict[i]);
-        if (status)
+        if (unlikely (status))
             goto fail;
 
         element = _cairo_array_index (&index, i);
         status = cff_dict_read (font->fd_dict[i], element->data, element->length);
-        if (status)
+        if (unlikely (status))
             goto fail;
 
         operand = cff_dict_get_operands (font->fd_dict[i], PRIVATE_OP, &size);
@@ -834,7 +834,7 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
         operand = decode_integer (operand, &size);
         decode_integer (operand, &offset);
         status = cff_dict_init (&font->fd_private_dict[i]);
-	if (status)
+	if (unlikely (status))
             goto fail;
 
         cff_index_init (&font->fd_local_sub_index[i]);
@@ -843,7 +843,7 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
                                                    &font->fd_local_sub_index[i],
                                                    font->data + offset,
                                                    size);
-        if (status)
+        if (unlikely (status))
             goto fail;
 
         /* Set integer operand to max value to use max size encoding to reserve
@@ -851,7 +851,7 @@ cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr)
         end_buf = encode_integer_max (buf, 0);
         end_buf = encode_integer_max (end_buf, 0);
         status = cff_dict_set_operands (font->fd_dict[i], PRIVATE_OP, buf, end_buf - buf);
-        if (status)
+        if (unlikely (status))
             goto fail;
     }
 
@@ -878,12 +878,12 @@ cairo_cff_font_read_top_dict (cairo_cff_font_t *font)
 
     cff_index_init (&index);
     status = cff_index_read (&index, &font->current_ptr, font->data_end);
-    if (status)
+    if (unlikely (status))
         goto fail;
 
     element = _cairo_array_index (&index, 0);
     status = cff_dict_read (font->top_dict, element->data, element->length);
-    if (status)
+    if (unlikely (status))
         goto fail;
 
     if (cff_dict_get_operands (font->top_dict, ROS_OP, &size) != NULL)
@@ -895,7 +895,7 @@ cairo_cff_font_read_top_dict (cairo_cff_font_t *font)
     decode_integer (operand, &offset);
     p = font->data + offset;
     status = cff_index_read (&font->charstrings_index, &p, font->data_end);
-    if (status)
+    if (unlikely (status))
         goto fail;
     font->num_glyphs = _cairo_array_num_elements (&font->charstrings_index);
 
@@ -903,13 +903,13 @@ cairo_cff_font_read_top_dict (cairo_cff_font_t *font)
         operand = cff_dict_get_operands (font->top_dict, FDSELECT_OP, &size);
         decode_integer (operand, &offset);
         status = cairo_cff_font_read_fdselect (font, font->data + offset);
-	if (status)
+	if (unlikely (status))
 	    goto fail;
 
         operand = cff_dict_get_operands (font->top_dict, FDARRAY_OP, &size);
         decode_integer (operand, &offset);
         status = cairo_cff_font_read_cid_fontdict (font, font->data + offset);
-	if (status)
+	if (unlikely (status))
 	    goto fail;
     } else {
         operand = cff_dict_get_operands (font->top_dict, PRIVATE_OP, &size);
@@ -920,7 +920,7 @@ cairo_cff_font_read_top_dict (cairo_cff_font_t *font)
 						   &font->local_sub_index,
 						   font->data + offset,
 						   size);
-	if (status)
+	if (unlikely (status))
 	    goto fail;
     }
 
@@ -928,22 +928,22 @@ cairo_cff_font_read_top_dict (cairo_cff_font_t *font)
     end_buf = encode_integer_max (buf, 0);
     status = cff_dict_set_operands (font->top_dict,
 	                            CHARSTRINGS_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            FDSELECT_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            FDARRAY_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            CHARSET_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     cff_dict_remove (font->top_dict, ENCODING_OP);
@@ -991,7 +991,7 @@ cairo_cff_font_read_font (cairo_cff_font_t *font)
 
     for (i = 0; i < ARRAY_LENGTH (font_read_funcs); i++) {
         status = font_read_funcs[i] (font);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -1012,26 +1012,26 @@ cairo_cff_font_set_ros_strings (cairo_cff_font_t *font)
     status = cff_index_append_copy (&font->strings_subset_index,
                                     (unsigned char *)registry,
                                     strlen(registry));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     sid2 = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index);
     status = cff_index_append_copy (&font->strings_subset_index,
                                     (unsigned char *)ordering,
 				    strlen(ordering));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     p = encode_integer (buf, sid1);
     p = encode_integer (p, sid2);
     p = encode_integer (p, 0);
     status = cff_dict_set_operands (font->top_dict, ROS_OP, buf, p - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     p = encode_integer (buf, font->scaled_font_subset->num_glyphs);
     status = cff_dict_set_operands (font->top_dict, CIDCOUNT_OP, buf, p - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1060,12 +1060,12 @@ cairo_cff_font_subset_dict_string(cairo_cff_font_t   *font,
     element = _cairo_array_index (&font->strings_index, sid - NUM_STD_STRINGS);
     sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index);
     status = cff_index_append (&font->strings_subset_index, element->data, element->length);
-    if (status)
+    if (unlikely (status))
         return status;
 
     p = encode_integer (buf, sid);
     status = cff_dict_set_operands (dict, operator, buf, p - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1092,7 +1092,7 @@ cairo_cff_font_subset_dict_strings (cairo_cff_font_t   *font,
 
     for (i = 0; i < ARRAY_LENGTH (dict_strings); i++) {
         status = cairo_cff_font_subset_dict_string (font, dict, dict_strings[i]);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -1112,7 +1112,7 @@ cairo_cff_font_subset_charstrings (cairo_cff_font_t  *font)
         status = cff_index_append (&font->charstrings_subset_index,
                                    element->data,
                                    element->length);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -1196,7 +1196,7 @@ cairo_cff_font_create_cid_fontdict (cairo_cff_font_t *font)
     end_buf = encode_integer_max (buf, 0);
     end_buf = encode_integer_max (end_buf, 0);
     status = cff_dict_set_operands (font->fd_dict[0], PRIVATE_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1209,17 +1209,17 @@ cairo_cff_font_subset_strings (cairo_cff_font_t *font)
     unsigned int i;
 
     status = cairo_cff_font_subset_dict_strings (font, font->top_dict);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (font->is_cid) {
         for (i = 0; i < font->num_subset_fontdicts; i++) {
             status = cairo_cff_font_subset_dict_strings (font, font->fd_dict[font->fd_subset_map[i]]);
-            if (status)
+            if (unlikely (status))
                 return status;
 
             status = cairo_cff_font_subset_dict_strings (font, font->fd_private_dict[font->fd_subset_map[i]]);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
     } else {
@@ -1235,22 +1235,22 @@ cairo_cff_font_subset_font (cairo_cff_font_t  *font)
     cairo_status_t status;
 
     status = cairo_cff_font_set_ros_strings (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_cff_font_subset_charstrings (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (font->is_cid)
         status = cairo_cff_font_subset_fontdict (font);
     else
         status = cairo_cff_font_create_cid_fontdict (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_cff_font_subset_strings (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     return status;
@@ -1298,11 +1298,11 @@ cairo_cff_font_write_name (cairo_cff_font_t *font)
     status = cff_index_append_copy (&index,
                                     (unsigned char *) font->subset_font_name,
                                     strlen(font->subset_font_name));
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     status = cff_index_write (&index, &font->output);
-    if (status)
+    if (unlikely (status))
         goto FAIL;
 
 FAIL:
@@ -1326,27 +1326,27 @@ cairo_cff_font_write_top_dict (cairo_cff_font_t *font)
 
     count = cpu_to_be16 (1);
     status = _cairo_array_append_multiple (&font->output, &count, 2);
-    if (status)
+    if (unlikely (status))
         return status;
     buf[0] = offset_size;
     status = _cairo_array_append (&font->output, buf);
-    if (status)
+    if (unlikely (status))
         return status;
     encode_index_offset (buf, offset_size, 1);
     status = _cairo_array_append_multiple (&font->output, buf, offset_size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     /* Reserve space for last element of offset array and update after
      * dict is written */
     offset_index = _cairo_array_num_elements (&font->output);
     status = _cairo_array_append_multiple (&font->output, buf, offset_size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     dict_start = _cairo_array_num_elements (&font->output);
     status = cff_dict_write (font->top_dict, &font->output);
-    if (status)
+    if (unlikely (status))
         return status;
     dict_size = _cairo_array_num_elements (&font->output) - dict_start;
 
@@ -1381,13 +1381,13 @@ cairo_cff_font_write_fdselect (cairo_cff_font_t  *font)
     if (font->is_cid) {
         data = 0;
         status = _cairo_array_append (&font->output, &data);
-        if (status)
+        if (unlikely (status))
             return status;
 
         for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
             data = font->fdselect_subset[i];
             status = _cairo_array_append (&font->output, &data);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
     } else {
@@ -1395,7 +1395,7 @@ cairo_cff_font_write_fdselect (cairo_cff_font_t  *font)
         uint16_t word;
 
         status = _cairo_array_grow_by (&font->output, 9);
-        if (status)
+        if (unlikely (status))
             return status;
 
         byte = 3;
@@ -1431,7 +1431,7 @@ cairo_cff_font_write_charset (cairo_cff_font_t  *font)
 
     cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSET_OP);
     status = _cairo_array_grow_by (&font->output, 5);
-    if (status)
+    if (unlikely (status))
         return status;
 
     byte = 2;
@@ -1470,22 +1470,22 @@ cairo_cff_font_write_cid_fontdict (cairo_cff_font_t *font)
     cairo_cff_font_set_topdict_operator_to_cur_pos (font, FDARRAY_OP);
     count = cpu_to_be16 (font->num_subset_fontdicts);
     status = _cairo_array_append_multiple (&font->output, &count, sizeof (uint16_t));
-    if (status)
+    if (unlikely (status))
         return status;
     status = _cairo_array_append (&font->output, &offset_size);
-    if (status)
+    if (unlikely (status))
         return status;
     status = _cairo_array_allocate (&font->output,
                                     (font->num_subset_fontdicts + 1)*offset_size,
                                     (void **) &offset_array);
-    if (status)
+    if (unlikely (status))
         return status;
     offset_base = _cairo_array_num_elements (&font->output) - 1;
     *offset_array++ = cpu_to_be32(1);
     for (i = 0; i < font->num_subset_fontdicts; i++) {
         status = cff_dict_write (font->fd_dict[font->fd_subset_map[i]],
                                  &font->output);
-        if (status)
+        if (unlikely (status))
             return status;
         *offset_array++ = cpu_to_be32(_cairo_array_num_elements (&font->output) - offset_base);
     }
@@ -1509,7 +1509,7 @@ cairo_cff_font_write_private_dict (cairo_cff_font_t   *font,
     /* Write private dict and update offset and size in top dict */
     font->private_dict_offset[dict_num] = _cairo_array_num_elements (&font->output);
     status = cff_dict_write (private_dict, &font->output);
-    if (status)
+    if (unlikely (status))
         return status;
 
     size = _cairo_array_num_elements (&font->output) - font->private_dict_offset[dict_num];
@@ -1548,7 +1548,7 @@ cairo_cff_font_write_local_sub (cairo_cff_font_t   *font,
         p = _cairo_array_index (&font->output, offset);
         memcpy (p, buf, buf_end - buf);
         status = cff_index_write (local_sub_index, &font->output);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -1569,7 +1569,7 @@ cairo_cff_font_write_cid_private_dict_and_local_sub (cairo_cff_font_t  *font)
                             i,
                             font->fd_dict[font->fd_subset_map[i]],
                             font->fd_private_dict[font->fd_subset_map[i]]);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
 
@@ -1579,7 +1579,7 @@ cairo_cff_font_write_cid_private_dict_and_local_sub (cairo_cff_font_t  *font)
                             i,
                             font->fd_private_dict[font->fd_subset_map[i]],
                            &font->fd_local_sub_index[font->fd_subset_map[i]]);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
     } else {
@@ -1587,14 +1587,14 @@ cairo_cff_font_write_cid_private_dict_and_local_sub (cairo_cff_font_t  *font)
                                                     0,
                                                     font->fd_dict[0],
                                                     font->private_dict);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
         status = cairo_cff_font_write_local_sub (font,
                                                  0,
                                                  font->private_dict,
                                                  &font->local_sub_index);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1625,7 +1625,7 @@ cairo_cff_font_write_subset (cairo_cff_font_t *font)
 
     for (i = 0; i < ARRAY_LENGTH (font_write_funcs); i++) {
         status = font_write_funcs[i] (font);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -1640,15 +1640,15 @@ cairo_cff_font_generate (cairo_cff_font_t  *font,
     cairo_int_status_t status;
 
     status = cairo_cff_font_read_font (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = cairo_cff_font_subset_font (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = cairo_cff_font_write_subset (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     *data = _cairo_array_index (&font->output, 0);
@@ -1674,7 +1674,7 @@ cairo_cff_font_create_set_widths (cairo_cff_font_t *font)
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
                                                  TT_TAG_hhea, 0,
                                                  (unsigned char*) &hhea, &size);
-    if (status)
+    if (unlikely (status))
         return status;
     num_hmetrics = be16_to_cpu (hhea.num_hmetrics);
 
@@ -1687,7 +1687,7 @@ cairo_cff_font_create_set_widths (cairo_cff_font_t *font)
                                                          TT_TAG_hmtx,
                                                          glyph_index * long_entry_size,
                                                          buf, &short_entry_size);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
         else
@@ -1696,7 +1696,7 @@ cairo_cff_font_create_set_widths (cairo_cff_font_t *font)
                                                          TT_TAG_hmtx,
                                                          (num_hmetrics - 1) * long_entry_size,
                                                          buf, &short_entry_size);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
         font->widths[i] = be16_to_cpu (*((int16_t*)buf));
@@ -1727,33 +1727,33 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     data_length = 0;
     status = backend->load_truetype_table( scaled_font_subset->scaled_font,
                                            TT_TAG_CFF, 0, NULL, &data_length);
-    if (status)
+    if (unlikely (status))
         return status;
 
     size = sizeof (tt_head_t);
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_head, 0,
                                            (unsigned char *) &head, &size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     size = sizeof (tt_hhea_t);
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_hhea, 0,
                                            (unsigned char *) &hhea, &size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     size = 0;
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_hmtx, 0, NULL, &size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     size = 0;
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_name, 0, NULL, &size);
-    if (status)
+    if (unlikely (status))
         return status;
 
     name = malloc (size);
@@ -1763,7 +1763,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_name, 0,
                                            (unsigned char *) name, &size);
-    if (status)
+    if (unlikely (status))
         goto fail1;
 
     font = malloc (sizeof (cairo_cff_font_t));
@@ -1777,7 +1777,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 
     _cairo_array_init (&font->output, sizeof (char));
     status = _cairo_array_grow_by (&font->output, 4096);
-    if (status)
+    if (unlikely (status))
 	goto fail2;
 
     font->subset_font_name = strdup (subset_name);
@@ -1840,7 +1840,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     }
 
     status = cairo_cff_font_create_set_widths (font);
-    if (status)
+    if (unlikely (status))
 	goto fail5;
 
     font->data_length = data_length;
@@ -1852,17 +1852,17 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     status = font->backend->load_truetype_table ( font->scaled_font_subset->scaled_font,
                                                   TT_TAG_CFF, 0, font->data,
                                                   &font->data_length);
-    if (status)
+    if (unlikely (status))
         goto fail6;
 
     font->data_end = font->data + font->data_length;
 
     status = cff_dict_init (&font->top_dict);
-    if (status)
+    if (unlikely (status))
 	goto fail6;
 
     status = cff_dict_init (&font->private_dict);
-    if (status)
+    if (unlikely (status))
 	goto fail7;
 
     cff_index_init (&font->strings_index);
@@ -1971,11 +1971,11 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
     unsigned int i;
 
     status = _cairo_cff_font_create (font_subset, &font, subset_name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_cff_font_generate (font, &data, &length);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     cff_subset->base_font = strdup (font->font_name);
@@ -2047,7 +2047,7 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
 
     _cairo_array_init (&font->output, sizeof (char));
     status = _cairo_array_grow_by (&font->output, 4096);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     font->subset_font_name = strdup (subset_name);
@@ -2080,11 +2080,11 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
     font->data_end = NULL;
 
     status = cff_dict_init (&font->top_dict);
-    if (status)
+    if (unlikely (status))
 	goto fail4;
 
     status = cff_dict_init (&font->private_dict);
-    if (status)
+    if (unlikely (status))
 	goto fail5;
 
     cff_index_init (&font->strings_index);
@@ -2147,37 +2147,37 @@ cairo_cff_font_fallback_generate (cairo_cff_font_t           *font,
     end_buf = encode_integer (end_buf, type2_subset->y_max);
     status = cff_dict_set_operands (font->top_dict,
 	                            FONTBBOX_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     end_buf = encode_integer_max (buf, 0);
     status = cff_dict_set_operands (font->top_dict,
 	                            CHARSTRINGS_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            FDSELECT_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            FDARRAY_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cff_dict_set_operands (font->top_dict,
 	                            CHARSET_OP, buf, end_buf - buf);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_cff_font_set_ros_strings (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Create CID FD dictionary */
     status = cairo_cff_font_create_cid_fontdict (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Create charstrings */
@@ -2188,12 +2188,12 @@ cairo_cff_font_fallback_generate (cairo_cff_font_t           *font,
                                    _cairo_array_index (charstring, 0),
                                    _cairo_array_num_elements (charstring));
 
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
     status = cairo_cff_font_write_subset (font);
-    if (status)
+    if (unlikely (status))
         return status;
 
     *data = _cairo_array_index (&font->output, 0);
@@ -2215,15 +2215,15 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
     cairo_type2_charstrings_t type2_subset;
 
     status = _cairo_cff_font_fallback_create (font_subset, &font, subset_name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_type2_charstrings_init (&type2_subset, font_subset);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     status = cairo_cff_font_fallback_generate (font, &type2_subset, &data, &length);
-    if (status)
+    if (unlikely (status))
 	goto fail2;
 
     cff_subset->base_font = strdup (font->font_name);
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index ce2a240..5c197ff 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -88,7 +88,7 @@ _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
 	cairo_status_t status;
 
 	status = _cairo_region_copy (&clip->region, &other->region);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_region_fini (&clip->region);
 	    cairo_surface_destroy (clip->surface);
 	    return status;
@@ -174,7 +174,7 @@ _cairo_clip_intersect_to_rectangle (cairo_clip_t            *clip,
     if (clip->path) {
         status = _cairo_clip_path_intersect_to_rectangle (clip->path,
                                                           rectangle);
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -191,7 +191,7 @@ _cairo_clip_intersect_to_rectangle (cairo_clip_t            *clip,
 
         _cairo_region_fini (&intersection);
 
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -228,7 +228,7 @@ _cairo_clip_intersect_to_region (cairo_clip_t      *clip,
 
     if (clip->has_region) {
 	status = _cairo_region_intersect (region, &clip->region, region);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -241,7 +241,7 @@ _cairo_clip_intersect_to_region (cairo_clip_t      *clip,
 
 	_cairo_region_fini (&clip_rect);
 
-        if (status)
+        if (unlikely (status))
             return status;
     }
 
@@ -302,7 +302,7 @@ _cairo_clip_intersect_path (cairo_clip_t       *clip,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_path_fixed_init_copy (&clip_path->path, path);
-    if (status) {
+    if (unlikely (status)) {
 	free (clip_path);
 	return status;
     }
@@ -362,7 +362,6 @@ _cairo_clip_intersect_region (cairo_clip_t    *clip,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     status = _cairo_traps_extract_region (traps, &region);
-
     if (status)
 	return status;
 
@@ -492,7 +491,7 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
 
     _cairo_pattern_fini (&pattern.base);
 
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (surface);
 	return status;
     }
@@ -517,7 +516,7 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
 
 	_cairo_pattern_fini (&pattern.base);
 
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_surface_destroy (surface);
 	    return status;
 	}
@@ -581,7 +580,7 @@ _cairo_clip_clip (cairo_clip_t       *clip,
 					      fill_rule,
 					      tolerance,
 					      &traps);
-    if (status)
+    if (unlikely (status))
 	goto bail;
 
     status = _cairo_clip_intersect_region (clip, &traps, target);
@@ -664,7 +663,7 @@ _cairo_clip_init_deep_copy (cairo_clip_t    *clip,
     } else {
         if (other->has_region) {
             status = _cairo_region_copy (&clip->region, &other->region);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 
 	    clip->has_region = TRUE;
@@ -679,7 +678,7 @@ _cairo_clip_init_deep_copy (cairo_clip_t    *clip,
 						   other->surface_rect.height,
 						   &dx, &dy,
 						   &clip->surface);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 
             clip->surface_rect = other->surface_rect;
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c
index eb4921e..0637758 100644
--- a/src/cairo-font-face.c
+++ b/src/cairo-font-face.c
@@ -467,10 +467,12 @@ cairo_toy_font_face_create (const char          *family,
 
     /* Make sure we've got valid UTF-8 for the family */
     status = _cairo_utf8_to_ucs4 (family, -1, NULL, NULL);
-    if (status == CAIRO_STATUS_INVALID_STRING)
-	return (cairo_font_face_t*) &_cairo_font_face_invalid_string;
-    else if (status)
+    if (unlikely (status)) {
+	if (status == CAIRO_STATUS_INVALID_STRING)
+	    return (cairo_font_face_t*) &_cairo_font_face_invalid_string;
+
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
+    }
 
     switch (slant) {
 	case CAIRO_FONT_SLANT_NORMAL:
@@ -523,11 +525,11 @@ cairo_toy_font_face_create (const char          *family,
     }
 
     status = _cairo_toy_font_face_init (font_face, family, slant, weight);
-    if (status)
+    if (unlikely (status))
 	goto UNWIND_FONT_FACE_MALLOC;
 
     status = _cairo_hash_table_insert (hash_table, &font_face->base.hash_entry);
-    if (status)
+    if (unlikely (status))
 	goto UNWIND_FONT_FACE_INIT;
 
     _cairo_toy_font_face_hash_table_unlock ();
@@ -614,7 +616,7 @@ _cairo_toy_font_face_scaled_font_create (void                *abstract_font_face
 	return font_face->base.status;
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (CAIRO_SCALED_FONT_BACKEND_DEFAULT != &_cairo_user_scaled_font_backend &&
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 4245448..a8d4101 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -438,12 +438,12 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face,
     }
 
     status = _cairo_ft_unscaled_font_init (unscaled, from_face, filename, id, font_face);
-    if (status)
+    if (unlikely (status))
 	goto UNWIND_UNSCALED_MALLOC;
 
     status = _cairo_hash_table_insert (font_map->hash_table,
 				       &unscaled->base.hash_entry);
-    if (status)
+    if (unlikely (status))
 	goto UNWIND_UNSCALED_FONT_INIT;
 
     _cairo_ft_unscaled_font_map_unlock ();
@@ -621,7 +621,7 @@ _compute_transform (cairo_ft_font_transform_t *sf,
     status = _cairo_matrix_compute_basis_scale_factors (scale,
 						  &x_scale, &y_scale,
 						  1);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* FreeType docs say this about x_scale and y_scale:
@@ -671,7 +671,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
     unscaled->current_scale = *scale;
 
     status = _compute_transform (&sf, scale);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     unscaled->x_scale = sf.x_scale;
@@ -1084,7 +1084,7 @@ _render_glyph_outline (FT_Face                    face,
 	}
 
 	status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1125,7 +1125,7 @@ _render_glyph_bitmap (FT_Face		      face,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /*
@@ -1212,13 +1212,13 @@ _transform_glyph_bitmap (cairo_matrix_t         * shape,
 
     transformed_to_original = original_to_transformed;
     status = cairo_matrix_invert (&transformed_to_original);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* We need to pad out the width to 32-bit intervals for cairo-xlib-surface.c */
     width = (width + 3) & ~3;
     image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
-    if (image->status)
+    if (unlikely (image->status))
 	return image->status;
 
     /* Initialize it to empty
@@ -1227,7 +1227,7 @@ _transform_glyph_bitmap (cairo_matrix_t         * shape,
 				            CAIRO_COLOR_TRANSPARENT,
 					    0, 0,
 					    width, height);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (image);
 	return status;
     }
@@ -1245,7 +1245,7 @@ _transform_glyph_bitmap (cairo_matrix_t         * shape,
 
     _cairo_pattern_fini (&pattern.base);
 
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (image);
 	return status;
     }
@@ -1527,7 +1527,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t	 *unscaled,
 			              font_face,
 				      font_matrix, ctm, options,
 				      &_cairo_ft_scaled_font_backend);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_unscaled_font_destroy (&unscaled->base);
 	free (scaled_font);
 	goto FAIL;
@@ -1535,7 +1535,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t	 *unscaled,
 
     status = _cairo_ft_unscaled_font_set_scale (unscaled,
 				                &scaled_font->base.scale);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_unscaled_font_destroy (&unscaled->base);
 	free (scaled_font);
 	goto FAIL;
@@ -1626,7 +1626,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t	      *toy_face,
 
     cairo_matrix_multiply (&scale, font_matrix, ctm);
     status = _compute_transform (&sf, &scale);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pattern = FcPatternCreate ();
@@ -1686,7 +1686,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t	      *toy_face,
     }
 
     status = _cairo_ft_font_options_substitute (font_options, pattern);
-    if (status)
+    if (unlikely (status))
 	goto FREE_PATTERN;
 
     FcDefaultSubstitute (pattern);
@@ -1863,7 +1863,7 @@ _decompose_glyph_outline (FT_Face		  face,
     }
 
     status = _cairo_path_fixed_close_path (path);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_path_fixed_destroy (path);
 	return status;
     }
@@ -1918,7 +1918,7 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
 
     status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
 				                &scaled_font->base.scale);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     /* Ignore global advance unconditionally */
@@ -2066,14 +2066,16 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
 	} else {
 	    status = _render_glyph_bitmap (face, &scaled_font->ft_options.base,
 					   &surface);
-	    if (status == CAIRO_STATUS_SUCCESS && unscaled->have_shape) {
+	    if (likely (status == CAIRO_STATUS_SUCCESS) &&
+		unscaled->have_shape)
+	    {
 		status = _transform_glyph_bitmap (&unscaled->current_shape,
 						  &surface);
-		if (status)
+		if (unlikely (status))
 		    cairo_surface_destroy (&surface->base);
 	    }
 	}
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	_cairo_scaled_glyph_set_surface (scaled_glyph,
@@ -2115,7 +2117,7 @@ _cairo_ft_scaled_glyph_init (void			*abstract_font,
 	else
 	    status = CAIRO_INT_STATUS_UNSUPPORTED;
 
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	_cairo_scaled_glyph_set_path (scaled_glyph,
@@ -2665,7 +2667,7 @@ cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font)
 
     status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
 				                &scaled_font->base.scale);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled);
 	status = _cairo_scaled_font_set_error (&scaled_font->base, status);
 	return NULL;
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 9f7892a..d7d91c9 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -113,11 +113,11 @@ _cairo_gstate_init (cairo_gstate_t  *gstate,
 	return _cairo_error (CAIRO_STATUS_NULL_POINTER);
 
     status = target->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = gstate->source->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -142,7 +142,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
 
     status = _cairo_stroke_style_init_copy (&gstate->stroke_style,
 					    &other->stroke_style);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     gstate->fill_rule = other->fill_rule;
@@ -155,7 +155,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
     _cairo_font_options_init_copy (&gstate->font_options , &other->font_options);
 
     status = _cairo_clip_init_copy (&gstate->clip, &other->clip);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_stroke_style_fini (&gstate->stroke_style);
 	cairo_font_face_destroy (gstate->font_face);
 	cairo_scaled_font_destroy (gstate->scaled_font);
@@ -227,7 +227,7 @@ _cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist)
 	*freelist = top->next;
 
     status = _cairo_gstate_init_copy (top, *gstate);
-    if (status) {
+    if (unlikely (status)) {
 	top->next = *freelist;
 	*freelist = top;
 	return status;
@@ -297,7 +297,7 @@ _cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child)
 
     _cairo_clip_reset (&gstate->clip);
     status = _cairo_clip_init_deep_copy (&gstate->clip, &gstate->next->clip, child);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* The clip is in surface backend coordinates for the previous target;
@@ -668,7 +668,7 @@ _cairo_gstate_transform (cairo_gstate_t	      *gstate,
 
     tmp = *matrix;
     status = cairo_matrix_invert (&tmp);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_gstate_unset_scaled_font (gstate);
@@ -827,7 +827,7 @@ _cairo_gstate_copy_transformed_pattern (cairo_gstate_t  *gstate,
 
 	if (_cairo_surface_has_device_transform (surface)) {
 	    status = _cairo_pattern_init_copy (*pattern, original);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    have_copy = TRUE;
@@ -839,7 +839,7 @@ _cairo_gstate_copy_transformed_pattern (cairo_gstate_t  *gstate,
     if (! _cairo_matrix_is_identity (ctm_inverse)) {
 	if (! have_copy) {
 	    status = _cairo_pattern_init_copy (*pattern, original);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    have_copy = TRUE;
@@ -884,12 +884,12 @@ _cairo_gstate_paint (cairo_gstate_t *gstate)
 	return gstate->source->status;
 
     status = _cairo_surface_set_clip (gstate->target, &gstate->clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pattern = &pattern_stack.base;
     status = _cairo_gstate_copy_transformed_source (gstate, &pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_surface_paint (gstate->target,
@@ -917,17 +917,17 @@ _cairo_gstate_mask (cairo_gstate_t  *gstate,
 	return gstate->source->status;
 
     status = _cairo_surface_set_clip (gstate->target, &gstate->clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     source_pattern = &source_pattern_stack.base;
     status = _cairo_gstate_copy_transformed_source (gstate, &source_pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     mask_pattern = &mask_pattern_stack.base;
     status = _cairo_gstate_copy_transformed_mask (gstate, &mask_pattern, mask);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     status = _cairo_surface_mask (gstate->target,
@@ -958,13 +958,13 @@ _cairo_gstate_stroke (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_surface_set_clip (gstate->target, &gstate->clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     source_pattern = &source_pattern_stack.base;
     status = _cairo_gstate_copy_transformed_source (gstate,
 	                                            &source_pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_surface_stroke (gstate->target,
@@ -1015,7 +1015,7 @@ _cairo_gstate_in_stroke (cairo_gstate_t	    *gstate,
 						&gstate->ctm_inverse,
 						gstate->tolerance,
 						&traps);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     *inside_ret = _cairo_traps_contain (&traps, x, y);
@@ -1037,12 +1037,12 @@ _cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
 	return gstate->source->status;
 
     status = _cairo_surface_set_clip (gstate->target, &gstate->clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pattern = &pattern_stack.base;
     status = _cairo_gstate_copy_transformed_source (gstate, &pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_surface_fill (gstate->target,
@@ -1219,7 +1219,7 @@ _cairo_gstate_int_clip_extents (cairo_gstate_t        *gstate,
     cairo_status_t status;
 
     status = _cairo_surface_get_extents (gstate->target, extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = _cairo_clip_intersect_to_rectangle (&gstate->clip, extents);
@@ -1239,7 +1239,7 @@ _cairo_gstate_clip_extents (cairo_gstate_t *gstate,
     cairo_status_t status;
 
     status = _cairo_gstate_int_clip_extents (gstate, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     px1 = extents.x;
@@ -1358,7 +1358,7 @@ _cairo_gstate_get_font_face (cairo_gstate_t     *gstate,
     cairo_status_t status;
 
     status = _cairo_gstate_ensure_font_face (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *font_face = gstate->font_face;
@@ -1373,7 +1373,7 @@ _cairo_gstate_get_scaled_font (cairo_gstate_t       *gstate,
     cairo_status_t status;
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *scaled_font = gstate->scaled_font;
@@ -1489,7 +1489,7 @@ _cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate)
 	return gstate->scaled_font->status;
 
     status = _cairo_gstate_ensure_font_face (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_surface_get_font_options (gstate->target, &options);
@@ -1501,7 +1501,7 @@ _cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate)
 					    &options);
 
     status = cairo_scaled_font_status (scaled_font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     gstate->scaled_font = scaled_font;
@@ -1514,7 +1514,7 @@ _cairo_gstate_get_font_extents (cairo_gstate_t *gstate,
 				cairo_font_extents_t *extents)
 {
     cairo_status_t status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_scaled_font_extents (gstate->scaled_font, extents);
@@ -1537,7 +1537,7 @@ _cairo_gstate_text_to_glyphs (cairo_gstate_t	         *gstate,
     cairo_status_t status;
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return cairo_scaled_font_text_to_glyphs (gstate->scaled_font, x, y,
@@ -1574,7 +1574,7 @@ _cairo_gstate_glyph_extents (cairo_gstate_t *gstate,
     cairo_status_t status;
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_scaled_font_glyph_extents (gstate->scaled_font,
@@ -1604,11 +1604,11 @@ _cairo_gstate_show_text_glyphs (cairo_gstate_t		   *gstate,
 	return gstate->source->status;
 
     status = _cairo_surface_set_clip (gstate->target, &gstate->clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (num_glyphs <= ARRAY_LENGTH (stack_transformed_glyphs)) {
@@ -1629,7 +1629,7 @@ _cairo_gstate_show_text_glyphs (cairo_gstate_t		   *gstate,
 
     source_pattern = &source_pattern_stack.base;
     status = _cairo_gstate_copy_transformed_source (gstate, &source_pattern);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_GLYPHS;
 
     /* Just in case */
@@ -1698,7 +1698,7 @@ _cairo_gstate_glyph_path (cairo_gstate_t      *gstate,
     cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs))
@@ -1712,7 +1712,7 @@ _cairo_gstate_glyph_path (cairo_gstate_t      *gstate,
 							glyphs, num_glyphs,
 							transformed_glyphs,
 							NULL);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_GLYPHS;
 
     status = _cairo_scaled_font_glyph_path (gstate->scaled_font,
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index b7a4f6c..ab8ab5e 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -870,7 +870,7 @@ _cairo_image_surface_set_attributes (cairo_image_surface_t      *surface,
 
     status = _cairo_image_surface_set_matrix (surface, &attributes->matrix,
 					      xc, yc);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     switch (attributes->extend) {
@@ -889,7 +889,7 @@ _cairo_image_surface_set_attributes (cairo_image_surface_t      *surface,
     }
 
     status = _cairo_image_surface_set_filter (surface, attributes->filter);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -968,13 +968,13 @@ _cairo_image_surface_composite (cairo_operator_t	op,
 					      (cairo_surface_t **) &src,
 					      (cairo_surface_t **) &mask,
 					      &src_attr, &mask_attr);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_image_surface_set_attributes (src, &src_attr,
 						  dst_x + width / 2.,
 						  dst_y + height / 2.);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACES;
 
     if (mask)
@@ -982,7 +982,7 @@ _cairo_image_surface_composite (cairo_operator_t	op,
 	status = _cairo_image_surface_set_attributes (mask, &mask_attr,
 						      dst_x + width / 2.,
 						      dst_y + height / 2.);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_SURFACES;
 
 	pixman_image_composite (_pixman_operator (op),
@@ -1156,13 +1156,13 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
 					     src_x, src_y, width, height,
 					     (cairo_surface_t **) &src,
 					     &attributes);
-    if (status)
+    if (unlikely (status))
 	goto finish;
 
     status = _cairo_image_surface_set_attributes (src, &attributes,
 						  dst_x + width / 2.,
 						  dst_y + height / 2.);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     switch (antialias) {
@@ -1353,7 +1353,7 @@ _cairo_image_surface_clone (cairo_image_surface_t	*surface,
     status = cairo_status (cr);
     cairo_destroy (cr);
 
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&clone->base);
 	return (cairo_image_surface_t *) _cairo_surface_create_in_error (status);
     }
diff --git a/src/cairo-lzw.c b/src/cairo-lzw.c
index 1241225..c179176 100644
--- a/src/cairo-lzw.c
+++ b/src/cairo-lzw.c
@@ -137,7 +137,7 @@ _lzw_buf_store_bits (lzw_buf_t *buf, uint16_t value, int num_bits)
     while (buf->pending_bits >= 8) {
 	if (buf->num_data >= buf->data_size) {
 	    status = _lzw_buf_grow (buf);
-	    if (status)
+	    if (unlikely (status))
 		return;
 	}
 	buf->data[buf->num_data++] = buf->pending >> (buf->pending_bits - 8);
@@ -167,7 +167,7 @@ _lzw_buf_store_pending  (lzw_buf_t *buf)
 
     if (buf->num_data >= buf->data_size) {
 	status = _lzw_buf_grow (buf);
-	if (status)
+	if (unlikely (status))
 	    return;
     }
 
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index cfaaf30..f32f489 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -197,7 +197,7 @@ _cairo_meta_surface_acquire_source_image (void			 *abstract_surface,
 						      surface->height_pixels);
 
     status = _cairo_meta_surface_replay (&surface->base, image);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (image);
 	return status;
     }
@@ -239,11 +239,11 @@ _cairo_meta_surface_paint (void			*abstract_surface,
     command->op = op;
 
     status = _cairo_pattern_init_snapshot (&command->source.base, source);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_COMMAND;
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     /* An optimisation that takes care to not replay what was done
@@ -285,15 +285,15 @@ _cairo_meta_surface_mask (void			*abstract_surface,
     command->op = op;
 
     status = _cairo_pattern_init_snapshot (&command->source.base, source);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_COMMAND;
 
     status = _cairo_pattern_init_snapshot (&command->mask.base, mask);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_MASK;
 
     return CAIRO_STATUS_SUCCESS;
@@ -336,15 +336,15 @@ _cairo_meta_surface_stroke (void			*abstract_surface,
     command->op = op;
 
     status = _cairo_pattern_init_snapshot (&command->source.base, source);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_COMMAND;
 
     status = _cairo_path_fixed_init_copy (&command->path, path);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     status = _cairo_stroke_style_init_copy (&command->style, style);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_PATH;
 
     command->ctm = *ctm;
@@ -353,7 +353,7 @@ _cairo_meta_surface_stroke (void			*abstract_surface,
     command->antialias = antialias;
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_STYLE;
 
     return CAIRO_STATUS_SUCCESS;
@@ -396,11 +396,11 @@ _cairo_meta_surface_fill (void			*abstract_surface,
     command->op = op;
 
     status = _cairo_pattern_init_snapshot (&command->source.base, source);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_COMMAND;
 
     status = _cairo_path_fixed_init_copy (&command->path, path);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     command->fill_rule = fill_rule;
@@ -408,7 +408,7 @@ _cairo_meta_surface_fill (void			*abstract_surface,
     command->antialias = antialias;
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_PATH;
 
     return CAIRO_STATUS_SUCCESS;
@@ -459,7 +459,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
     command->op = op;
 
     status = _cairo_pattern_init_snapshot (&command->source.base, source);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_COMMAND;
 
     command->utf8 = NULL;
@@ -499,7 +499,7 @@ _cairo_meta_surface_show_text_glyphs (void			    *abstract_surface,
     command->scaled_font = cairo_scaled_font_reference (scaled_font);
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SCALED_FONT;
 
     return CAIRO_STATUS_SUCCESS;
@@ -575,7 +575,7 @@ _cairo_meta_surface_intersect_clip_path (void		    *dst,
 
     if (path) {
 	status = _cairo_path_fixed_init_copy (&command->path, path);
-	if (status) {
+	if (unlikely (status)) {
 	    free (command);
 	    return status;
 	}
@@ -590,7 +590,7 @@ _cairo_meta_surface_intersect_clip_path (void		    *dst,
     command->antialias = antialias;
 
     status = _cairo_array_append (&meta->commands, &command);
-    if (status) {
+    if (unlikely (status)) {
 	if (path)
 	    _cairo_path_fixed_fini (&command->path);
 	free (command);
@@ -766,7 +766,7 @@ _cairo_meta_surface_get_path (cairo_surface_t	 *surface,
 	    ASSERT_NOT_REACHED;
 	}
 
-	if (status)
+	if (unlikely (status))
 	    break;
     }
 
@@ -814,14 +814,14 @@ _cairo_meta_surface_replay_internal (cairo_surface_t	     *surface,
 	 * ensure the current clip gets set on the surface. */
 	if (command->header.type != CAIRO_COMMAND_INTERSECT_CLIP_PATH) {
 	    status = _cairo_surface_set_clip (target, &clip);
-	    if (status)
+	    if (unlikely (status))
 		break;
 	}
 
 	dev_path = _cairo_command_get_path (command);
 	if (dev_path && has_device_transform) {
 	    status = _cairo_path_fixed_init_copy (&path_copy, dev_path);
-	    if (status)
+	    if (unlikely (status))
 		break;
 	    _cairo_path_fixed_transform (&path_copy, device_transform);
 	    dev_path = &path_copy;
@@ -986,7 +986,7 @@ _cairo_meta_surface_replay_internal (cairo_surface_t	     *surface,
 	    }
 	}
 
-	if (status)
+	if (unlikely (status))
 	    break;
     }
 
diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index 397b0ef..c487603 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -287,7 +287,7 @@ _cairo_validate_text_clusters (const char		   *utf8,
 
 	/* Make sure we've got valid UTF-8 for the cluster */
 	status = _cairo_utf8_to_ucs4 (utf8+n_bytes, cluster_bytes, NULL, NULL);
-	if (status)
+	if (unlikely (status))
 	    return CAIRO_STATUS_INVALID_CLUSTERS;
 
 	n_bytes  += cluster_bytes ;
@@ -730,7 +730,7 @@ _cairo_intern_string (const char **str_inout, int len)
 
 	    status = _cairo_hash_table_insert (_cairo_intern_string_ht,
 					       &istring->hash_entry);
-	    if (status)
+	    if (unlikely (status))
 		free (istring);
 	} else
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -738,7 +738,7 @@ _cairo_intern_string (const char **str_inout, int len)
 
     CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex);
 
-    if (status == CAIRO_STATUS_SUCCESS)
+    if (likely (status == CAIRO_STATUS_SUCCESS))
 	*str_inout = istring->string;
 
     return status;
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index 9a58aac..780bd50 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -696,7 +696,7 @@ _cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream,
     cairo_status_t status;
 
     status = abstract_stream->status;
-    if (status)
+    if (unlikely (status))
 	return _cairo_output_stream_destroy (abstract_stream);
 
     stream = (memory_stream_t *) abstract_stream;
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index bb542ff..70b728e 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -99,7 +99,7 @@ _cairo_paginated_surface_create (cairo_surface_t				*target,
 
     surface->meta = _cairo_meta_surface_create (content, width, height);
     status = cairo_surface_status (surface->meta);
-    if (status)
+    if (unlikely (status))
 	goto FAIL_CLEANUP_SURFACE;
 
     surface->page_num = 1;
@@ -151,7 +151,7 @@ _cairo_paginated_surface_set_size (cairo_surface_t	*surface,
     paginated_surface->meta = _cairo_meta_surface_create (paginated_surface->content,
 							  width, height);
     status = cairo_surface_status (paginated_surface->meta);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -215,7 +215,7 @@ _cairo_paginated_surface_acquire_source_image (void	       *abstract_surface,
     cairo_rectangle_int_t extents;
 
     status = _cairo_surface_get_extents (surface->target, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     image = _cairo_paginated_surface_create_image_surface (surface,
@@ -223,7 +223,7 @@ _cairo_paginated_surface_acquire_source_image (void	       *abstract_surface,
 							   extents.height);
 
     status = _cairo_meta_surface_replay (surface->meta, image);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (image);
 	return status;
     }
@@ -267,7 +267,7 @@ _paint_fallback_image (cairo_paginated_surface_t *surface,
     cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale);
 
     status = _cairo_meta_surface_replay (surface->meta, image);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_IMAGE;
 
     _cairo_pattern_init_for_surface (&pattern, image);
@@ -318,7 +318,7 @@ _paint_page (cairo_paginated_surface_t *surface)
 
 	 _cairo_analysis_surface_get_bounding_box (analysis, &bbox);
 	 status = surface->backend->set_bounding_box (surface->target, &bbox);
-	 if (status)
+	 if (unlikely (status))
 	     goto FAIL;
      }
 
@@ -327,7 +327,7 @@ _paint_page (cairo_paginated_surface_t *surface)
 
 	status = surface->backend->set_fallback_images_required (surface->target,
 								 has_fallbacks);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
     }
 
@@ -360,7 +360,7 @@ _paint_page (cairo_paginated_surface_t *surface)
 						    surface->target,
 						    CAIRO_META_REGION_NATIVE);
 	assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
     }
 
@@ -375,7 +375,7 @@ _paint_page (cairo_paginated_surface_t *surface)
 	box.p2.x = surface->width;
 	box.p2.y = surface->height;
 	status = _paint_fallback_image (surface, &box);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
     }
 
@@ -393,19 +393,19 @@ _paint_page (cairo_paginated_surface_t *surface)
 						     CAIRO_FILL_RULE_WINDING,
 						     CAIRO_GSTATE_TOLERANCE_DEFAULT,
 						     CAIRO_ANTIALIAS_DEFAULT);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	region = _cairo_analysis_surface_get_unsupported (analysis);
 
 	num_boxes = 0;
 	status = _cairo_region_get_boxes (region, &num_boxes, &boxes);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	for (i = 0; i < num_boxes; i++) {
 	    status = _paint_fallback_image (surface, &boxes[i]);
-	    if (status) {
+	    if (unlikely (status)) {
                 _cairo_region_boxes_fini (region, boxes);
 		goto FAIL;
             }
@@ -439,11 +439,11 @@ _cairo_paginated_surface_copy_page (void *abstract_surface)
     cairo_paginated_surface_t *surface = abstract_surface;
 
     status = _start_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _paint_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->page_num++;
@@ -466,20 +466,20 @@ _cairo_paginated_surface_show_page (void *abstract_surface)
     cairo_paginated_surface_t *surface = abstract_surface;
 
     status = _start_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _paint_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_surface_show_page (surface->target);
     status = cairo_surface_status (surface->target);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_surface_status (surface->meta);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_surface_destroy (surface->meta);
@@ -488,7 +488,7 @@ _cairo_paginated_surface_show_page (void *abstract_surface)
 						surface->width,
 						surface->height);
     status = cairo_surface_status (surface->meta);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->page_num++;
diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index d37b375..7af91d2 100644
--- a/src/cairo-path-fill.c
+++ b/src/cairo-path-fill.c
@@ -177,18 +177,18 @@ _cairo_path_fixed_fill_to_traps (cairo_path_fixed_t *path,
 					  _cairo_filler_curve_to,
 					  _cairo_filler_close_path,
 					  &filler);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     _cairo_polygon_close (&filler.polygon);
     status = _cairo_polygon_status (&filler.polygon);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_bentley_ottmann_tessellate_polygon (filler.traps,
 							&filler.polygon,
 							fill_rule);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
 BAIL:
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index ba46760..04d547c 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -372,7 +372,7 @@ _cairo_path_fixed_move_to (cairo_path_fixed_t  *path,
 	*last_move_to_point = point;
     } else {
 	status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_MOVE_TO, &point, 1);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -426,7 +426,7 @@ _cairo_path_fixed_line_to (cairo_path_fixed_t *path,
     else
 	status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1);
 
-    if (status)
+    if (unlikely (status))
 	return status;
 
     path->current_point = point;
@@ -467,12 +467,12 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t	*path,
     if (! path->has_current_point) {
 	status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_MOVE_TO,
 					&point[0], 1);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     path->current_point = point[2];
@@ -519,13 +519,13 @@ _cairo_path_fixed_close_path (cairo_path_fixed_t *path)
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_path_fixed_move_to (path,
 					path->last_move_point.x,
 					path->last_move_point.y);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -692,7 +692,7 @@ _cairo_path_fixed_interpret (const cairo_path_fixed_t		*path,
 		status = (*close_path) (closure);
 		break;
 	    }
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    if (forward) {
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 3c02a94..f2b9e7a 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -175,7 +175,7 @@ _cairo_stroker_init (cairo_stroker_t		*stroker,
     status = _cairo_pen_init (&stroker->pen,
 		              stroke_style->line_width / 2.0,
 			      tolerance, ctm);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stroker->has_current_face = FALSE;
@@ -658,22 +658,22 @@ _cairo_stroker_add_caps (cairo_stroker_t *stroker)
 	_compute_face (&stroker->first_point, &slope, dx, dy, stroker, &face);
 
 	status = _cairo_stroker_add_leading_cap (stroker, &face);
-	if (status)
+	if (unlikely (status))
 	    return status;
 	status = _cairo_stroker_add_trailing_cap (stroker, &face);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     if (stroker->has_first_face) {
 	status = _cairo_stroker_add_leading_cap (stroker, &stroker->first_face);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     if (stroker->has_current_face) {
 	status = _cairo_stroker_add_trailing_cap (stroker, &stroker->current_face);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -761,7 +761,7 @@ _cairo_stroker_move_to (void *closure, cairo_point_t *point)
 
     /* Cap the start and end of the previous sub path as needed */
     status = _cairo_stroker_add_caps (stroker);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stroker->first_point = *point;
@@ -806,13 +806,13 @@ _cairo_stroker_line_to (void *closure, cairo_point_t *point)
     _compute_normalized_device_slope (&slope_dx, &slope_dy, stroker->ctm_inverse, NULL);
 
     status = _cairo_stroker_add_sub_edge (stroker, p1, p2, &dev_slope, slope_dx, slope_dy, &start, &end);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (stroker->has_current_face) {
 	/* Join with final face from previous segment */
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &start);
-	if (status)
+	if (unlikely (status))
 	    return status;
     } else if (!stroker->has_first_face) {
 	/* Save sub path's first face in case needed for closing join */
@@ -890,7 +890,7 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 						  &dev_slope,
 						  slope_dx, slope_dy,
 						  &sub_start, &sub_end);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    if (stroker->has_current_face) {
@@ -898,7 +898,7 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 		status = _cairo_stroker_join (stroker,
 					      &stroker->current_face,
 					      &sub_start);
-		if (status)
+		if (unlikely (status))
 		    return status;
 
 		stroker->has_current_face = FALSE;
@@ -909,14 +909,14 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 	    } else {
 		/* Cap dash start if not connecting to a previous segment */
 		status = _cairo_stroker_add_leading_cap (stroker, &sub_start);
-		if (status)
+		if (unlikely (status))
 		    return status;
 	    }
 
 	    if (remain) {
 		/* Cap dash end if not at end of segment */
 		status = _cairo_stroker_add_trailing_cap (stroker, &sub_end);
-		if (status)
+		if (unlikely (status))
 		    return status;
 	    } else {
 		stroker->current_face = sub_end;
@@ -927,7 +927,7 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 		/* Cap final face from previous segment */
 		status = _cairo_stroker_add_trailing_cap (stroker,
 							  &stroker->current_face);
-		if (status)
+		if (unlikely (status))
 		    return status;
 
 		stroker->has_current_face = FALSE;
@@ -955,7 +955,7 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 
 	status = _cairo_stroker_add_leading_cap (stroker,
 						 &stroker->current_face);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	stroker->has_current_face = TRUE;
@@ -986,7 +986,7 @@ _cairo_stroker_curve_to (void *closure,
 					    a, b, c, d);
     if (status == CAIRO_INT_STATUS_DEGENERATE)
 	return _cairo_stroker_line_to (closure, d);
-    else if (status)
+    else if (unlikely (status))
 	return status;
 
     initial_slope_dx = _cairo_fixed_to_double (spline_pen.spline.initial_slope.dx);
@@ -1014,7 +1014,7 @@ _cairo_stroker_curve_to (void *closure,
 
     if (stroker->has_current_face) {
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &start);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_PEN;
     } else if (! stroker->has_first_face) {
 	stroker->first_face = start;
@@ -1037,7 +1037,7 @@ _cairo_stroker_curve_to (void *closure,
     extra_points[3].y -= end.point.y;
 
     status = _cairo_pen_add_points (&spline_pen.pen, extra_points, 4);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_PEN;
 
     status = _cairo_pen_stroke_spline (&spline_pen,
@@ -1121,18 +1121,18 @@ _cairo_stroker_close_path (void *closure)
 	status = _cairo_stroker_line_to_dashed (stroker, &stroker->first_point);
     else
 	status = _cairo_stroker_line_to (stroker, &stroker->first_point);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (stroker->has_first_face && stroker->has_current_face) {
 	/* Join first and final faces of sub path */
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &stroker->first_face);
-	if (status)
+	if (unlikely (status))
 	    return status;
     } else {
 	/* Cap the start and end of the sub path as needed */
 	status = _cairo_stroker_add_caps (stroker);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1175,7 +1175,7 @@ _cairo_path_fixed_stroke_to_traps (cairo_path_fixed_t	*path,
     status = _cairo_stroker_init (&stroker, stroke_style,
 			          ctm, ctm_inverse, tolerance,
 				  traps);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (stroker.style->dash)
@@ -1194,7 +1194,7 @@ _cairo_path_fixed_stroke_to_traps (cairo_path_fixed_t	*path,
 					      _cairo_stroker_curve_to,
 					      _cairo_stroker_close_path,
 					      &stroker);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     /* Cap the start and end of the final sub path as needed */
@@ -1386,7 +1386,7 @@ _cairo_rectilinear_stroker_emit_segments (cairo_rectilinear_stroker_t *stroker)
 	}
 
 	status = _cairo_traps_tessellate_rectangle (stroker->traps, a, b);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1403,7 +1403,7 @@ _cairo_rectilinear_stroker_move_to (void		*closure,
     cairo_status_t status;
 
     status = _cairo_rectilinear_stroker_emit_segments (stroker);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stroker->current_point = *point;
@@ -1449,13 +1449,13 @@ _cairo_rectilinear_stroker_close_path (void *closure)
 
     status = _cairo_rectilinear_stroker_line_to (stroker,
 						 &stroker->first_point);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stroker->open_sub_path = FALSE;
 
     status = _cairo_rectilinear_stroker_emit_segments (stroker);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1512,7 +1512,7 @@ _cairo_path_fixed_stroke_rectilinear (cairo_path_fixed_t	*path,
 					  NULL,
 					  _cairo_rectilinear_stroker_close_path,
 					  &rectilinear_stroker);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_rectilinear_stroker_emit_segments (&rectilinear_stroker);
@@ -1520,7 +1520,7 @@ _cairo_path_fixed_stroke_rectilinear (cairo_path_fixed_t	*path,
 BAIL:
     _cairo_rectilinear_stroker_fini (&rectilinear_stroker);
 
-    if (status)
+    if (unlikely (status))
 	_cairo_traps_clear (traps);
 
     return status;
diff --git a/src/cairo-path.c b/src/cairo-path.c
index c6639f3..855b85f 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -127,7 +127,7 @@ _cairo_path_count (cairo_path_t		*path,
 					      &cpc);
     }
 
-    if (status)
+    if (unlikely (status))
 	return -1;
 
     return cpc.count;
@@ -283,7 +283,7 @@ _cairo_path_populate (cairo_path_t		*path,
 					  &cpp);
     }
 
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Sanity check the count */
@@ -474,7 +474,7 @@ _cairo_path_append_to_context (const cairo_path_t	*path,
 	}
 
 	status = cairo_status (cr);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index bdcafe7..56fa28a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -181,7 +181,7 @@ _cairo_pattern_init_copy (cairo_pattern_t	*pattern,
 	cairo_status_t status;
 
 	status = _cairo_gradient_pattern_init_copy (dst, src);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
     } break;
@@ -203,7 +203,7 @@ _cairo_pattern_init_snapshot (cairo_pattern_t       *pattern,
     /* We don't bother doing any fancy copy-on-write implementation
      * for the pattern's data. It's generally quite tiny. */
     status = _cairo_pattern_init_copy (pattern, other);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* But we do let the surface snapshot stuff be as fancy as it
@@ -276,7 +276,7 @@ _cairo_pattern_create_copy (cairo_pattern_t	  **pattern,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_pattern_init_copy (*pattern, other);
-    if (status) {
+    if (unlikely (status)) {
 	free (*pattern);
 	return status;
     }
@@ -872,7 +872,7 @@ _cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern,
 
     if (pattern->n_stops >= pattern->stops_size) {
         cairo_status_t status = _cairo_pattern_gradient_grow (pattern);
-	if (status) {
+	if (unlikely (status)) {
 	    status = _cairo_pattern_set_error (&pattern->base, status);
 	    return;
 	}
@@ -1063,7 +1063,7 @@ cairo_pattern_set_matrix (cairo_pattern_t      *pattern,
 
     inverse = *matrix;
     status = cairo_matrix_invert (&inverse);
-    if (status)
+    if (unlikely (status))
 	status = _cairo_pattern_set_error (pattern, status);
 }
 slim_hidden_def (cairo_pattern_set_matrix);
@@ -1519,7 +1519,7 @@ _cairo_pattern_acquire_surface_for_solid (const cairo_solid_pattern_t	     *patt
 						    dst))
     {
 	status = _cairo_surface_reset (solid_surface_cache.cache[i].surface);
-	if (status)
+	if (unlikely (status))
 	    goto UNLOCK;
 
 	goto DONE;
@@ -1531,7 +1531,7 @@ _cairo_pattern_acquire_surface_for_solid (const cairo_solid_pattern_t	     *patt
 							dst))
 	{
 	    status = _cairo_surface_reset (solid_surface_cache.cache[i].surface);
-	    if (status)
+	    if (unlikely (status))
 		goto UNLOCK;
 
 	    goto DONE;
@@ -1551,11 +1551,11 @@ _cairo_pattern_acquire_surface_for_solid (const cairo_solid_pattern_t	     *patt
 	    /* Reuse the surface instead of evicting */
 
 	    status = _cairo_surface_reset (surface);
-	    if (status)
+	    if (unlikely (status))
 		goto EVICT;
 
 	    status = _cairo_surface_repaint_solid_pattern_surface (dst, surface, pattern);
-	    if (status)
+	    if (unlikely (status))
 		goto EVICT;
 
 	    cairo_surface_reference (surface);
@@ -1839,14 +1839,14 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
 	int w, h;
 
 	status = _cairo_surface_get_extents (surface, &extents);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	status = _cairo_surface_clone_similar (dst, surface,
 					       extents.x, extents.y,
 					       extents.width, extents.height,
 					       &extents.x, &extents.y, &src);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	w = 2 * extents.width;
@@ -1914,14 +1914,14 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
 
 	cairo_surface_destroy (src);
 
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	attr->extend = CAIRO_EXTEND_REPEAT;
     }
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     /* We first transform the rectangle to the coordinate space of the
@@ -1969,7 +1969,7 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
 					   extents.x, extents.y,
 					   extents.width, extents.height,
 					   &x, &y, out);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     if (x != 0 || y != 0) {
@@ -2184,7 +2184,7 @@ _cairo_pattern_acquire_surfaces (const cairo_pattern_t	    *src,
 					     src_x, src_y,
 					     width, height,
 					     src_out, src_attributes);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     if (mask == NULL) {
@@ -2196,7 +2196,7 @@ _cairo_pattern_acquire_surfaces (const cairo_pattern_t	    *src,
 					     mask_x, mask_y,
 					     width, height,
 					     mask_out, mask_attributes);
-    if (status)
+    if (unlikely (status))
 	_cairo_pattern_release_surface (src, *src_out, src_attributes);
 
   BAIL:
@@ -2237,7 +2237,7 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
 	status = _cairo_surface_get_extents (surface, &surface_extents);
 	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
 	    goto UNBOUNDED;
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	/* The filter can effectively enlarge the extents of the
diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index d363805..9d5bcba 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -447,7 +447,7 @@ _cairo_pdf_operators_emit_path (cairo_pdf_operators_t	*pdf_operators,
 
     word_wrap = _word_wrap_stream_create (pdf_operators->stream, 72);
     status = _cairo_output_stream_get_status (word_wrap);
-    if (status)
+    if (unlikely (status))
 	return _cairo_output_stream_destroy (word_wrap);
 
     info.output = word_wrap;
@@ -488,7 +488,7 @@ _cairo_pdf_operators_clip (cairo_pdf_operators_t	*pdf_operators,
 						 path,
 						 &pdf_operators->cairo_to_pdf,
 						 CAIRO_LINE_CAP_ROUND);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -714,7 +714,7 @@ _cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t	*pdf_operators,
 
     if (pdf_operators->in_text_object) {
 	status = _cairo_pdf_operators_end_text (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -753,7 +753,7 @@ _cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t	*pdf_operators,
 	_cairo_matrix_factor_out_scale (&m, &scale);
 	path_transform = m;
 	status = cairo_matrix_invert (&path_transform);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	cairo_matrix_multiply (&m, &m, &pdf_operators->cairo_to_pdf);
@@ -762,7 +762,7 @@ _cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t	*pdf_operators,
     status = _cairo_pdf_operators_emit_stroke_style (pdf_operators, style, scale);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (has_ctm) {
@@ -778,7 +778,7 @@ _cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t	*pdf_operators,
 					     path,
 					     &path_transform,
 					     style->line_cap);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (pdf_operators->stream, "%s", pdf_operator);
@@ -815,7 +815,7 @@ _cairo_pdf_operators_fill (cairo_pdf_operators_t	*pdf_operators,
 
     if (pdf_operators->in_text_object) {
 	status = _cairo_pdf_operators_end_text (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -823,7 +823,7 @@ _cairo_pdf_operators_fill (cairo_pdf_operators_t	*pdf_operators,
 					     path,
 					     &pdf_operators->cairo_to_pdf,
 					     CAIRO_LINE_CAP_ROUND);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     switch (fill_rule) {
@@ -964,7 +964,7 @@ _cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t    *pdf_operators)
 
     word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, 72);
     status = _cairo_output_stream_get_status (word_wrap_stream);
-    if (status)
+    if (unlikely (status))
 	return _cairo_output_stream_destroy (word_wrap_stream);
 
     /* Check if glyph advance used to position every glyph */
@@ -1023,7 +1023,7 @@ _cairo_pdf_operators_set_text_matrix (cairo_pdf_operators_t  *pdf_operators,
     /* We require the matrix to be invertable. */
     inverse = *matrix;
     status = cairo_matrix_invert (&inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pdf_operators->text_matrix = *matrix;
@@ -1112,7 +1112,7 @@ _cairo_pdf_operators_set_font_subset (cairo_pdf_operators_t             *pdf_ope
 	status = pdf_operators->use_font_subset (subset_glyph->font_id,
 						 subset_glyph->subset_id,
 						 pdf_operators->use_font_subset_closure);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
     pdf_operators->font_id = subset_glyph->font_id;
@@ -1143,7 +1143,7 @@ _cairo_pdf_operators_end_text (cairo_pdf_operators_t    *pdf_operators)
     cairo_status_t status;
 
     status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (pdf_operators->stream, "ET\n");
@@ -1177,7 +1177,7 @@ _cairo_pdf_operators_begin_actualtext (cairo_pdf_operators_t *pdf_operators,
     _cairo_output_stream_printf (pdf_operators->stream, "/Span << /ActualText <feff");
     if (utf8_len) {
 	status = _cairo_utf8_to_utf16 (utf8, utf8_len, &utf16, &utf16_len);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	for (i = 0; i < utf16_len; i++) {
@@ -1212,11 +1212,11 @@ _cairo_pdf_operators_emit_glyph (cairo_pdf_operators_t             *pdf_operator
 	pdf_operators->subset_id != subset_glyph->subset_id)
     {
 	status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_set_font_subset (pdf_operators, subset_glyph);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	pdf_operators->is_new_text_object = FALSE;
@@ -1241,14 +1241,14 @@ _cairo_pdf_operators_emit_glyph (cairo_pdf_operators_t             *pdf_operator
 	fabs(y - pdf_operators->cur_y) > GLYPH_POSITION_TOLERANCE)
     {
 	status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	x = glyph->x;
 	y = glyph->y;
 	cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &x, &y);
 	status = _cairo_pdf_operators_set_text_position (pdf_operators, x, y);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	x = 0.0;
@@ -1296,14 +1296,14 @@ _cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t      *pdf_operators,
 						       utf8,
 						       utf8_len,
 						       &subset_glyph);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (subset_glyph.utf8_is_mapped || utf8_len < 0) {
 	    status = _cairo_pdf_operators_emit_glyph (pdf_operators,
 						      glyphs,
 						      &subset_glyph);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    return CAIRO_STATUS_SUCCESS;
@@ -1313,11 +1313,11 @@ _cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t      *pdf_operators,
     /* Fallback to using ActualText to map zero or more glyphs to a
      * unicode string. */
     status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_begin_actualtext (pdf_operators, utf8, utf8_len);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cur_glyph = glyphs;
@@ -1329,13 +1329,13 @@ _cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t      *pdf_operators,
 						       cur_glyph->index,
 						       NULL, -1,
 						       &subset_glyph);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_emit_glyph (pdf_operators,
 						  cur_glyph,
 						  &subset_glyph);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD))
@@ -1344,7 +1344,7 @@ _cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t      *pdf_operators,
 	    cur_glyph++;
     }
     status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_end_actualtext (pdf_operators);
@@ -1374,13 +1374,13 @@ _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t	  *pdf_operators,
     status = cairo_matrix_invert (&pdf_operators->font_matrix_inverse);
     if (status == CAIRO_STATUS_INVALID_MATRIX)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pdf_operators->is_new_text_object = FALSE;
     if (pdf_operators->in_text_object == FALSE) {
 	status = _cairo_pdf_operators_begin_text (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	/* Force Tm and Tf to be emitted when starting a new text
@@ -1401,7 +1401,7 @@ _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t	  *pdf_operators,
 	! _cairo_matrix_scale_equal (&pdf_operators->text_matrix, &text_matrix))
     {
 	status = _cairo_pdf_operators_flush_glyphs (pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	x = glyphs[0].x;
@@ -1412,7 +1412,7 @@ _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t	  *pdf_operators,
 	status = _cairo_pdf_operators_set_text_matrix (pdf_operators, &text_matrix);
 	if (status == CAIRO_STATUS_INVALID_MATRIX)
 	    return CAIRO_STATUS_SUCCESS;
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1432,7 +1432,7 @@ _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t	  *pdf_operators,
 							clusters[i].num_glyphs,
 							cluster_flags,
 							scaled_font);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    cur_text += clusters[i].num_bytes;
@@ -1448,7 +1448,7 @@ _cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t	  *pdf_operators,
 							1,
 							FALSE,
 							scaled_font);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
     }
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 9790250..9926e6f 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -207,7 +207,7 @@ _cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface)
     object.offset = _cairo_output_stream_get_position (surface->output);
 
     status = _cairo_array_append (&surface->objects, &object);
-    if (status) {
+    if (unlikely (status)) {
 	resource.id = 0;
 	return resource;
     }
@@ -551,7 +551,7 @@ cairo_pdf_surface_set_size (cairo_surface_t	*surface,
     cairo_status_t status;
 
     status = _extract_pdf_surface (surface, &pdf_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -562,7 +562,7 @@ cairo_pdf_surface_set_size (cairo_surface_t	*surface,
     status = _cairo_paginated_surface_set_size (pdf_surface->paginated_surface,
 						width_in_points,
 						height_in_points);
-    if (status)
+    if (unlikely (status))
 	status = _cairo_surface_set_error (surface, status);
 }
 
@@ -639,7 +639,7 @@ _cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface,
     }
 
     status = _cairo_array_append (&res->alphas, &alpha);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *index = _cairo_array_num_elements (&res->alphas) - 1;
@@ -702,7 +702,7 @@ _cairo_pdf_surface_add_font (unsigned int        font_id,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = _cairo_array_append (&surface->fonts, &font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return _cairo_array_append (&res->fonts, &font);
@@ -898,7 +898,7 @@ _cairo_pdf_surface_add_pdf_pattern (cairo_pdf_surface_t		*surface,
     }
 
     status = _cairo_pattern_create_copy (&pdf_pattern.pattern, pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pdf_pattern.pattern_res = _cairo_pdf_surface_new_object (surface);
@@ -936,7 +936,7 @@ _cairo_pdf_surface_add_pdf_pattern (cairo_pdf_surface_t		*surface,
     *gstate_res = pdf_pattern.gstate_res;
 
     status = _cairo_array_append (&surface->patterns, &pdf_pattern);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_pattern_destroy (pdf_pattern.pattern);
 	return status;
     }
@@ -1022,7 +1022,7 @@ _cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface)
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (surface->pdf_stream.compressed) {
@@ -1151,7 +1151,7 @@ _cairo_pdf_surface_open_knockout_group (cairo_pdf_surface_t  *surface)
     cairo_status_t status;
 
     status = _cairo_pdf_surface_open_group (surface, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->group_stream.is_knockout = TRUE;
@@ -1169,7 +1169,7 @@ _cairo_pdf_surface_close_group (cairo_pdf_surface_t *surface,
     assert (surface->group_stream.active == TRUE);
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (surface->compress_content) {
@@ -1237,7 +1237,7 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t  *surface,
 					    surface->compress_content,
 					    NULL);
     }
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->content = surface->pdf_stream.self;
@@ -1256,12 +1256,12 @@ _cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface)
     assert (surface->group_stream.active == FALSE);
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->output, "Q\n");
     status = _cairo_pdf_surface_close_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pdf_surface_update_object (surface, surface->content_resources);
@@ -1414,7 +1414,7 @@ _cairo_pdf_surface_has_fallback_images (void		*abstract_surface,
 
     surface->has_fallback_images = has_fallbacks;
     status = _cairo_pdf_surface_open_content_stream (surface, has_fallbacks);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1515,7 +1515,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t	*surface,
 					     "   /BitsPerComponent %d\n",
 					     image->width, image->height,
 					     image->format == CAIRO_FORMAT_A1 ? 1 : 8);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_ALPHA;
 
     *stream_ret = surface->pdf_stream.self;
@@ -1601,7 +1601,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
 	image->format == CAIRO_FORMAT_A8 ||
 	image->format == CAIRO_FORMAT_A1) {
 	status = _cairo_pdf_surface_emit_smask (surface, image, &smask);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_RGB;
 
 	if (smask.id)
@@ -1645,7 +1645,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
 						 IMAGE_DICTIONARY,
 						 image->width, image->height,
 						 interpolate);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_RGB;
 
 #undef IMAGE_DICTIONARY
@@ -1727,7 +1727,7 @@ _cairo_pdf_surface_emit_jpeg_image (cairo_pdf_surface_t   *surface,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (info.num_components != 1 && info.num_components != 3)
@@ -1747,7 +1747,7 @@ _cairo_pdf_surface_emit_jpeg_image (cairo_pdf_surface_t   *surface,
 					     info.height,
 					     info.num_components == 1 ? "/DeviceGray" : "/DeviceRGB",
 					     info.bits_per_component);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *res = surface->pdf_stream.self;
@@ -1789,7 +1789,7 @@ _cairo_pdf_surface_emit_image_surface (cairo_pdf_surface_t     *surface,
 	return status;
 
     status = _cairo_surface_acquire_source_image (pattern->surface, &image, &image_extra);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     pad_image = &image->base;
@@ -1826,13 +1826,13 @@ _cairo_pdf_surface_emit_image_surface (cairo_pdf_surface_t     *surface,
 					   rect.width,
 					   rect.height);
 	_cairo_pattern_fini (&pad_pattern.base);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
     }
 
     status = _cairo_pdf_surface_emit_image (surface, (cairo_image_surface_t *)pad_image,
 					    resource, pattern->base.filter);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     *width = ((cairo_image_surface_t *)pad_image)->width;
@@ -1862,7 +1862,7 @@ _cairo_pdf_surface_emit_meta_surface (cairo_pdf_surface_t  *surface,
     int alpha = 0;
 
     status = _cairo_surface_get_extents (meta_surface, &meta_extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     old_width = surface->width;
@@ -1879,13 +1879,13 @@ _cairo_pdf_surface_emit_meta_surface (cairo_pdf_surface_t  *surface,
     surface->paginated_mode = CAIRO_PAGINATED_MODE_RENDER;
     _cairo_pdf_group_resources_clear (&surface->resources);
     status = _cairo_pdf_surface_open_content_stream (surface, TRUE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *resource = surface->content;
     if (cairo_surface_get_content (meta_surface) == CAIRO_CONTENT_COLOR) {
 	status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -1898,11 +1898,11 @@ _cairo_pdf_surface_emit_meta_surface (cairo_pdf_surface_t  *surface,
     status = _cairo_meta_surface_replay_region (meta_surface, &surface->base,
 						CAIRO_META_REGION_NATIVE);
     assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_surface_set_clip (&surface->base, old_clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_close_content_stream (surface);
@@ -1940,11 +1940,11 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t	*surface,
 	status = _cairo_pdf_surface_emit_meta_surface (surface,
 						       meta_surface,
 						       &pattern_resource);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_surface_get_extents (meta_surface, &pattern_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	pattern_width = pattern_extents.width;
@@ -1957,12 +1957,12 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t	*surface,
 							&pattern_height,
 							&origin_x,
 							&origin_y);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     status = _cairo_surface_get_extents (&surface->base, &surface_extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     bbox_x = pattern_width;
@@ -2074,7 +2074,7 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t	*surface,
 					     pdf_p2d.x0, pdf_p2d.y0,
 					     pattern_resource.id,
 					     pattern_resource.id);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (_cairo_surface_is_meta (pattern->surface)) {
@@ -2112,7 +2112,7 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t	*surface,
     }
 
     status = _cairo_pdf_surface_close_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return _cairo_output_stream_get_status (surface->output);
@@ -2244,14 +2244,14 @@ _cairo_pdf_surface_emit_stitched_colorgradient (cairo_pdf_surface_t    *surface,
                                                                    &stops[i],
                                                                    &stops[i+1],
                                                                    &stops[i].resource);
-            if (status)
+            if (unlikely (status))
                 return status;
         } else {
             status = cairo_pdf_surface_emit_rgb_linear_function (surface,
                                                                  &stops[i],
                                                                  &stops[i+1],
                                                                  &stops[i].resource);
-            if (status)
+            if (unlikely (status))
                 return status;
         }
     }
@@ -2380,7 +2380,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t      *surface,
                                                              &stops[0],
                                                              &stops[1],
                                                              color_function);
-        if (status)
+        if (unlikely (status))
             goto BAIL;
 
         if (emit_alpha) {
@@ -2388,7 +2388,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t      *surface,
                                                                    &stops[0],
                                                                    &stops[1],
                                                                    alpha_function);
-            if (status)
+            if (unlikely (status))
                 goto BAIL;
         }
     } else {
@@ -2399,7 +2399,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t      *surface,
                                                                  stops,
                                                                  FALSE,
                                                                  color_function);
-        if (status)
+        if (unlikely (status))
             goto BAIL;
 
         if (emit_alpha) {
@@ -2408,7 +2408,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t      *surface,
                                                                      stops,
                                                                      TRUE,
                                                                      alpha_function);
-            if (status)
+            if (unlikely (status))
                 goto BAIL;
         }
     }
@@ -2510,7 +2510,7 @@ cairo_pdf_surface_emit_transparency_group (cairo_pdf_surface_t  *surface,
 					     surface->height,
 					     gradient_mask.id,
 					     gradient_mask.id);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->output,
@@ -2525,7 +2525,7 @@ cairo_pdf_surface_emit_transparency_group (cairo_pdf_surface_t  *surface,
                                  surface->height);
 
      status = _cairo_pdf_surface_close_stream (surface);
-     if (status)
+     if (unlikely (status))
 	return status;
 
     smask_resource = _cairo_pdf_surface_new_object (surface);
@@ -2648,7 +2648,7 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t    *surface,
                                                     &pattern->base,
                                                     &color_function,
                                                     &alpha_function);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (pattern->base.base.extend == CAIRO_EXTEND_REPEAT ||
@@ -2658,7 +2658,7 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t    *surface,
 							     &color_function,
 							     repeat_begin,
 							     repeat_end);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (alpha_function.id != 0) {
@@ -2667,7 +2667,7 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t    *surface,
 								 &alpha_function,
 								 repeat_begin,
 								 repeat_end);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
     }
@@ -2747,13 +2747,13 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t    *surface,
                                      ">>\n"
                                      "endobj\n");
         status = _cairo_pdf_surface_add_pattern (surface, mask_resource);
-        if (status)
+        if (unlikely (status))
             return status;
 
 	status = cairo_pdf_surface_emit_transparency_group (surface,
 						            pdf_pattern->gstate_res,
 							    mask_resource);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -2779,7 +2779,7 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t    *surface,
                                                     &pattern->base,
                                                     &color_function,
                                                     &alpha_function);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pat_to_pdf = pattern->base.base.matrix;
@@ -2870,7 +2870,7 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t    *surface,
 	status = cairo_pdf_surface_emit_transparency_group (surface,
 						            pdf_pattern->gstate_res,
 							    mask_resource);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -2953,7 +2953,7 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 	    surface->current_color_is_stroke != is_stroke)
 	{
 	    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_output_stream_printf (surface->output,
@@ -2977,11 +2977,11 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 	    surface->current_color_alpha != solid_color->alpha)
 	{
 	    status = _cairo_pdf_surface_add_alpha (surface, solid_color->alpha, &alpha);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_output_stream_printf (surface->output,
@@ -2993,15 +2993,15 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 	surface->current_pattern_is_solid_color = TRUE;
     } else {
 	status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_pattern (surface, pattern_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	/* fill-stroke calls select_pattern twice. Don't save if the
@@ -3035,7 +3035,7 @@ _cairo_pdf_surface_unselect_pattern (cairo_pdf_surface_t *surface)
 
     if (surface->select_pattern_gstate_saved) {
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output, "Q\n");
@@ -3053,11 +3053,11 @@ _cairo_pdf_surface_show_page (void *abstract_surface)
     cairo_int_status_t status;
 
     status = _cairo_pdf_surface_close_content_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_write_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pdf_surface_clear (surface);
@@ -3096,7 +3096,7 @@ _cairo_pdf_surface_intersect_clip_path (void			*abstract_surface,
 
     if (path == NULL) {
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output, "Q q\n");
@@ -3183,7 +3183,7 @@ _cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t	*surface,
 
     if (utf8 && *utf8) {
 	status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -3225,7 +3225,7 @@ _cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t		*surface,
 					      NULL,
 					      surface->compress_content,
 					      NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->output,
@@ -3277,7 +3277,7 @@ _cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t		*surface,
         }
 	status = _cairo_pdf_surface_emit_unicode_for_glyph (surface,
 							    font_subset->utf8[i + 1]);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -3317,14 +3317,14 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 					     NULL,
 					     TRUE,
 					     "   /Subtype /CIDFontType0C\n");
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stream = surface->pdf_stream.self;
     _cairo_output_stream_write (surface->output,
 				subset->data, subset->data_length);
     status = _cairo_pdf_surface_close_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_emit_to_unicode_stream (surface,
@@ -3432,7 +3432,7 @@ _cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t	     *surface,
     snprintf (name, sizeof name, "CairoFont-%d-%d",
               font_subset->font_id, font_subset->subset_id);
     status = _cairo_cff_subset_init (&subset, name, font_subset);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset);
@@ -3453,7 +3453,7 @@ _cairo_pdf_surface_emit_cff_fallback_font (cairo_pdf_surface_t	       *surface,
     snprintf (name, sizeof name, "CairoFont-%d-%d",
               font_subset->font_id, font_subset->subset_id);
     status = _cairo_cff_fallback_init (&subset, name, font_subset);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset);
@@ -3490,13 +3490,13 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
 					     "   /Length3 0\n",
 					     subset->header_length,
 					     subset->data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     stream = surface->pdf_stream.self;
     _cairo_output_stream_write (surface->output, subset->data, length);
     status = _cairo_pdf_surface_close_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_emit_to_unicode_stream (surface,
@@ -3584,7 +3584,7 @@ _cairo_pdf_surface_emit_type1_font_subset (cairo_pdf_surface_t		*surface,
     snprintf (name, sizeof name, "CairoFont-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
     status = _cairo_type1_subset_init (&subset, name, font_subset, FALSE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset);
@@ -3605,7 +3605,7 @@ _cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t	*surface,
     snprintf (name, sizeof name, "CairoFont-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
     status = _cairo_type1_fallback_init_binary (&subset, name, font_subset);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset);
@@ -3634,7 +3634,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_truetype_subset_init (&subset, font_subset);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_open_stream (surface,
@@ -3642,7 +3642,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 					     TRUE,
 					     "   /Length1 %lu\n",
 					     subset.data_length);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_truetype_subset_fini (&subset);
 	return status;
     }
@@ -3651,7 +3651,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_write (surface->output,
 				subset.data, subset.data_length);
     status = _cairo_pdf_surface_close_stream (surface);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_truetype_subset_fini (&subset);
 	return status;
     }
@@ -3822,7 +3822,7 @@ _cairo_pdf_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_su
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface,
 							   font_subset->glyphs[i]);
-	if (status)
+	if (unlikely (status))
 	    break;
     }
 
@@ -3880,7 +3880,7 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
 						 NULL,
 						 surface->compress_content,
 						 NULL);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	glyphs[i] = surface->pdf_stream.self;
@@ -3889,11 +3889,11 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
 							font_subset->glyphs[i],
 							&bbox,
 							&widths[i]);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	status = _cairo_pdf_surface_close_stream (surface);
-	if (status)
+	if (unlikely (status))
 	    break;
 
         if (i == 0) {
@@ -3913,7 +3913,7 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
         }
     }
     cairo_surface_destroy (type3_surface);
-    if (status) {
+    if (unlikely (status)) {
 	free (glyphs);
 	free (widths);
 	return status;
@@ -4072,19 +4072,19 @@ _cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface)
     status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets,
 						      _cairo_pdf_surface_analyze_user_font_subset,
 						      surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets,
                                                           _cairo_pdf_surface_emit_unscaled_font_subset,
                                                           surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets,
                                                         _cairo_pdf_surface_emit_scaled_font_subset,
                                                         surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets,
@@ -4159,14 +4159,14 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 
     /* Create mask group */
     status = _cairo_pdf_surface_open_group (surface, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pattern_res.id = 0;
     gstate_res.id = 0;
     status = _cairo_pdf_surface_add_pdf_pattern (surface, group->mask, NULL,
 						 &pattern_res, &gstate_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -4178,17 +4178,17 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 	smask_group->source = cairo_pattern_reference (group->mask);
 	smask_group->source_res = pattern_res;
 	status = _cairo_pdf_surface_add_smask_group (surface, smask_group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (smask_group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4197,7 +4197,7 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 				     smask_group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, group->mask, pattern_res, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4205,24 +4205,24 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 				     surface->width, surface->height);
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     status = _cairo_pdf_surface_close_group (surface, &mask_group);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Create source group */
     status = _cairo_pdf_surface_open_group (surface, &group->source_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     pattern_res.id = 0;
     gstate_res.id = 0;
     status = _cairo_pdf_surface_add_pdf_pattern (surface, group->source, NULL,
 						 &pattern_res, &gstate_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -4234,17 +4234,17 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 	smask_group->source = cairo_pattern_reference (group->source);
 	smask_group->source_res = pattern_res;
 	status = _cairo_pdf_surface_add_smask_group (surface, smask_group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (smask_group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4253,7 +4253,7 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 				     smask_group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, group->source, pattern_res, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4261,12 +4261,12 @@ _cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t	*surface,
 				     surface->width, surface->height);
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     status = _cairo_pdf_surface_close_group (surface, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Create an smask based on the alpha component of mask_group */
@@ -4319,14 +4319,14 @@ _cairo_pdf_surface_write_smask_group (cairo_pdf_surface_t     *surface,
 	return _cairo_pdf_surface_write_mask_group (surface, group);
 
     status = _cairo_pdf_surface_open_group (surface, &group->group_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_select_pattern (surface,
 						group->source,
 						group->source_res,
 						group->operation == PDF_STROKE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     switch (group->operation) {
@@ -4359,11 +4359,11 @@ _cairo_pdf_surface_write_smask_group (cairo_pdf_surface_t     *surface,
 							group->scaled_font);
 	break;
     }
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_unselect_pattern (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_close_group (surface, NULL);
@@ -4398,14 +4398,14 @@ _cairo_pdf_surface_write_patterns_and_smask_groups (cairo_pdf_surface_t *surface
 	for (; group_index < _cairo_array_num_elements (&surface->smask_groups); group_index++) {
 	    _cairo_array_copy_element (&surface->smask_groups, group_index, &group);
 	    status = _cairo_pdf_surface_write_smask_group (surface, group);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
 
 	for (; pattern_index < _cairo_array_num_elements (&surface->patterns); pattern_index++) {
 	    _cairo_array_copy_element (&surface->patterns, pattern_index, &pattern);
 	    status = _cairo_pdf_surface_emit_pattern (surface, &pattern);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
     }
@@ -4423,7 +4423,7 @@ _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
     _cairo_pdf_group_resources_clear (&surface->resources);
     if (surface->has_fallback_images) {
 	status = _cairo_pdf_surface_open_knockout_group (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	len = _cairo_array_num_elements (&surface->knockout_group);
@@ -4433,34 +4433,34 @@ _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
 					 "/x%d Do\n",
 					 res.id);
 	    status = _cairo_pdf_surface_add_xobject (surface, res);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
 	_cairo_output_stream_printf (surface->output,
 				     "/x%d Do\n",
 				     surface->content.id);
 	status = _cairo_pdf_surface_add_xobject (surface, surface->content);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_close_group (surface, &knockout);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_pdf_group_resources_clear (&surface->resources);
 	status = _cairo_pdf_surface_open_content_stream (surface, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
 				     "/x%d Do\n",
 				     knockout.id);
 	status = _cairo_pdf_surface_add_xobject (surface, knockout);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_close_content_stream (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4490,11 +4490,11 @@ _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
 				 surface->content_resources.id);
 
     status = _cairo_array_append (&surface->pages, &page);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_write_patterns_and_smask_groups (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -4512,7 +4512,7 @@ _cairo_pdf_surface_analyze_surface_pattern_transparency (cairo_pdf_surface_t
     status = _cairo_surface_acquire_source_image (pattern->surface,
 						  &image,
 						  &image_extra);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (image->base.status)
@@ -4697,11 +4697,11 @@ _cairo_pdf_surface_start_fallback (cairo_pdf_surface_t *surface)
     cairo_status_t status;
 
     status = _cairo_pdf_surface_close_content_stream (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_array_append (&surface->knockout_group, &surface->content);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pdf_group_resources_clear (&surface->resources);
@@ -4723,7 +4723,7 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 	return _cairo_pdf_surface_analyze_operation (surface, op, source);
     } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) {
 	status = _cairo_pdf_surface_start_fallback (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4735,7 +4735,7 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 						 &pattern_res, &gstate_res);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -4745,27 +4745,27 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 
 	group->operation = PDF_PAINT;
 	status = _cairo_pattern_create_copy (&group->source, source);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 	group->source_res = pattern_res;
 	status = _cairo_pdf_surface_add_smask_group (surface, group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4774,7 +4774,7 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 				     group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4782,7 +4782,7 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
 				     surface->width, surface->height);
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4815,7 +4815,7 @@ _cairo_pdf_surface_mask	(void			*abstract_surface,
 						     mask_status);
     } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) {
 	status = _cairo_pdf_surface_start_fallback (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4828,12 +4828,12 @@ _cairo_pdf_surface_mask	(void			*abstract_surface,
 
     group->operation = PDF_MASK;
     status = _cairo_pattern_create_copy (&group->source, source);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_pdf_smask_group_destroy (group);
 	return status;
     }
     status = _cairo_pattern_create_copy (&group->mask, mask);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_pdf_smask_group_destroy (group);
 	return status;
     }
@@ -4844,21 +4844,21 @@ _cairo_pdf_surface_mask	(void			*abstract_surface,
     }
 
     status = _cairo_pdf_surface_add_smask_group (surface, group);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_pdf_smask_group_destroy (group);
 	return status;
     }
 
     status = _cairo_pdf_surface_add_smask (surface, group->group_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_add_xobject (surface, group->source_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->output,
@@ -4897,7 +4897,7 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 						 &pattern_res, &gstate_res);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -4907,13 +4907,13 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 
 	group->operation = PDF_STROKE;
 	status = _cairo_pattern_create_copy (&group->source, source);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 	group->source_res = pattern_res;
 	status = _cairo_path_fixed_init_copy (&group->path, path);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
@@ -4922,21 +4922,21 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 	group->ctm = *ctm;
 	group->ctm_inverse = *ctm_inverse;
 	status = _cairo_pdf_surface_add_smask_group (surface, group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -4945,7 +4945,7 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 				     group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, TRUE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_stroke (&surface->pdf_operators,
@@ -4953,11 +4953,11 @@ _cairo_pdf_surface_stroke (void			*abstract_surface,
 					      style,
 					      ctm,
 					      ctm_inverse);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4983,7 +4983,7 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
 	return _cairo_pdf_surface_analyze_operation (surface, op, source);
     } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) {
 	status = _cairo_pdf_surface_start_fallback (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -4995,7 +4995,7 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
 						 &pattern_res, &gstate_res);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -5005,34 +5005,34 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
 
 	group->operation = PDF_FILL;
 	status = _cairo_pattern_create_copy (&group->source, source);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 	group->source_res = pattern_res;
 	status = _cairo_path_fixed_init_copy (&group->path, path);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 
 	group->fill_rule = fill_rule;
 	status = _cairo_pdf_surface_add_smask_group (surface, group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -5041,17 +5041,17 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
 				     group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_fill (&surface->pdf_operators,
 					    path,
 					    fill_rule);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -5104,7 +5104,7 @@ _cairo_pdf_surface_fill_stroke (void		     *abstract_surface,
 						 extents,
 						 &fill_pattern_res,
 						 &gstate_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     assert (gstate_res.id == 0);
@@ -5116,7 +5116,7 @@ _cairo_pdf_surface_fill_stroke (void		     *abstract_surface,
 						 extents,
 						 &stroke_pattern_res,
 						 &gstate_res);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     assert (gstate_res.id == 0);
@@ -5125,12 +5125,12 @@ _cairo_pdf_surface_fill_stroke (void		     *abstract_surface,
      * select both at the same time */
     status = _cairo_pdf_surface_select_pattern (surface, fill_source,
 						fill_pattern_res, FALSE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_select_pattern (surface, stroke_source,
 						stroke_pattern_res, TRUE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_fill_stroke (&surface->pdf_operators,
@@ -5139,11 +5139,11 @@ _cairo_pdf_surface_fill_stroke (void		     *abstract_surface,
 					       stroke_style,
 					       stroke_ctm,
 					       stroke_ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_surface_unselect_pattern (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return _cairo_output_stream_get_status (surface->output);
@@ -5185,7 +5185,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 						 &pattern_res, &gstate_res);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	return CAIRO_STATUS_SUCCESS;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (gstate_res.id != 0) {
@@ -5195,7 +5195,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
 	group->operation = PDF_SHOW_GLYPHS;
 	status = _cairo_pattern_create_copy (&group->source, source);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
@@ -5233,21 +5233,21 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 
 	group->scaled_font = cairo_scaled_font_reference (scaled_font);
 	status = _cairo_pdf_surface_add_smask_group (surface, group);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_pdf_smask_group_destroy (group);
 	    return status;
 	}
 
 	status = _cairo_pdf_surface_add_smask (surface, gstate_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_add_xobject (surface, group->group_res);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
@@ -5256,7 +5256,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 				     group->group_res.id);
     } else {
 	status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	/* Each call to show_glyphs() with a transclucent pattern must
@@ -5265,7 +5265,7 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 	 * each other. */
 	if (! _cairo_pattern_is_opaque (source)) {
 	    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
 
@@ -5275,11 +5275,11 @@ _cairo_pdf_surface_show_text_glyphs (void			*abstract_surface,
 							clusters, num_clusters,
 							cluster_flags,
 							scaled_font);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_surface_unselect_pattern (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 43d344a..21ed8e3 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -162,7 +162,7 @@ _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
 	pen->vertices[pen->num_vertices-num_points+i].point = point[i];
 
     status = _cairo_hull_compute (pen->vertices, &pen->num_vertices);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pen_compute_slopes (pen);
@@ -491,7 +491,7 @@ _cairo_pen_stroke_spline (cairo_pen_stroke_spline_t	*stroker,
 			     1);
 
     status = _cairo_polygon_status (&stroker->polygon);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_bentley_ottmann_tessellate_polygon (traps,
@@ -548,7 +548,7 @@ _cairo_pen_stroke_spline_init (cairo_pen_stroke_spline_t *stroker,
     }
 
     status = _cairo_pen_init_copy (&stroker->pen, pen);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_spline_fini (&stroker->spline);
 	return status;
     }
diff --git a/src/cairo-png.c b/src/cairo-png.c
index 5bb658c..69df0f3 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -159,7 +159,7 @@ write_png (cairo_surface_t	*surface,
 
     if (status == CAIRO_INT_STATUS_UNSUPPORTED)
 	return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-    else if (status)
+    else if (unlikely (status))
         return status;
 
     /* PNG complains about "Image width or height is zero in IHDR" */
@@ -361,7 +361,7 @@ stream_write_func (png_structp png, png_bytep data, png_size_t size)
 
     png_closure = png_get_io_ptr (png);
     status = png_closure->write_func (png_closure->closure, data, size);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_status_t *error = png_get_error_ptr (png);
 	if (*error == CAIRO_STATUS_SUCCESS)
 	    *error = status;
@@ -486,7 +486,7 @@ stream_read_func (png_structp png, png_bytep data, png_size_t size)
 
     png_closure = png_get_io_ptr (png);
     status = png_closure->read_func (png_closure->closure, data, size);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_status_t *error = png_get_error_ptr (png);
 	if (*error == CAIRO_STATUS_SUCCESS)
 	    *error = status;
@@ -544,7 +544,7 @@ read_png (struct png_read_closure_t *png_closure)
     png_get_IHDR (png, info,
                   &png_width, &png_height, &depth,
                   &color_type, &interlace, NULL, NULL);
-    if (status) { /* catch any early warnings */
+    if (unlikely (status)) { /* catch any early warnings */
 	surface = _cairo_surface_create_in_error (status);
 	goto BAIL;
     }
@@ -637,7 +637,7 @@ read_png (struct png_read_closure_t *png_closure)
     png_read_image (png, row_pointers);
     png_read_end (png, info);
 
-    if (status) { /* catch any late warnings - probably hit an error already */
+    if (unlikely (status)) { /* catch any late warnings - probably hit an error already */
 	surface = _cairo_surface_create_in_error (status);
 	goto BAIL;
     }
@@ -654,7 +654,7 @@ read_png (struct png_read_closure_t *png_closure)
     status = _cairo_memory_stream_destroy (png_closure->png_data,
 					   &mime_data,
 					   &mime_data_length);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (surface);
 	surface = _cairo_surface_create_in_error (status);
 	goto BAIL;
@@ -666,7 +666,7 @@ read_png (struct png_read_closure_t *png_closure)
 					  mime_data_length,
 					  free,
 					  mime_data);
-    if (status) {
+    if (unlikely (status)) {
 	free (mime_data);
 	cairo_surface_destroy (surface);
 	surface = _cairo_surface_create_in_error (status);
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 0c9ef7f..43219e5 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -262,7 +262,7 @@ _cairo_ps_surface_emit_type1_font_subset (cairo_ps_surface_t		*surface,
     snprintf (name, sizeof name, "f-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
     status = _cairo_type1_subset_init (&subset, name, font_subset, TRUE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* FIXME: Figure out document structure convention for fonts */
@@ -293,7 +293,7 @@ _cairo_ps_surface_emit_type1_font_fallback (cairo_ps_surface_t		*surface,
     snprintf (name, sizeof name, "f-%d-%d",
 	      font_subset->font_id, font_subset->subset_id);
     status = _cairo_type1_fallback_init_hex (&subset, name, font_subset);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* FIXME: Figure out document structure convention for fonts */
@@ -322,7 +322,7 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
     unsigned int i, begin, end;
 
     status = _cairo_truetype_subset_init (&subset, font_subset);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* FIXME: Figure out document structure convention for fonts */
@@ -463,7 +463,7 @@ _cairo_ps_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_sub
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface,
 							   font_subset->glyphs[i]);
-	if (status)
+	if (unlikely (status))
 	    break;
 
     }
@@ -527,7 +527,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 							font_subset->glyphs[i],
 							&bbox,
 							&width);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	_cairo_output_stream_printf (surface->final_stream,
@@ -549,7 +549,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
         }
     }
     cairo_surface_destroy (type3_surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->final_stream,
@@ -635,19 +635,19 @@ _cairo_ps_surface_emit_font_subsets (cairo_ps_surface_t *surface)
     status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets,
 						      _cairo_ps_surface_analyze_user_font_subset,
 						      surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets,
                                                           _cairo_ps_surface_emit_unscaled_font_subset,
                                                           surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets,
                                                         _cairo_ps_surface_emit_scaled_font_subset,
                                                         surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets,
@@ -730,7 +730,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
 
     surface->stream = _cairo_output_stream_create_for_file (surface->tmpfile);
     status = _cairo_output_stream_get_status (surface->stream);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_OUTPUT_STREAM;
 
     surface->font_subsets = _cairo_scaled_font_subsets_create_simple ();
@@ -935,7 +935,7 @@ cairo_ps_surface_restrict_to_level (cairo_surface_t  *surface,
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1010,7 +1010,7 @@ cairo_ps_surface_set_eps (cairo_surface_t	*surface,
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1035,7 +1035,7 @@ cairo_ps_surface_get_eps (cairo_surface_t	*surface)
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return FALSE;
     }
@@ -1069,7 +1069,7 @@ cairo_ps_surface_set_size (cairo_surface_t	*surface,
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1082,7 +1082,7 @@ cairo_ps_surface_set_size (cairo_surface_t	*surface,
     status = _cairo_paginated_surface_set_size (ps_surface->paginated_surface,
 						width_in_points,
 						height_in_points);
-    if (status)
+    if (unlikely (status))
 	status = _cairo_surface_set_error (surface, status);
 }
 
@@ -1183,7 +1183,7 @@ cairo_ps_surface_dsc_comment (cairo_surface_t	*surface,
     char *comment_copy;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1207,7 +1207,7 @@ cairo_ps_surface_dsc_comment (cairo_surface_t	*surface,
     }
 
     status = _cairo_array_append (ps_surface->dsc_comment_target, &comment_copy);
-    if (status) {
+    if (unlikely (status)) {
 	free (comment_copy);
 	status = _cairo_surface_set_error (surface, status);
 	return;
@@ -1237,7 +1237,7 @@ cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface)
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1272,7 +1272,7 @@ cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface)
     cairo_status_t status;
 
     status = _extract_ps_surface (surface, &ps_surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -1304,11 +1304,11 @@ _cairo_ps_surface_finish (void *abstract_surface)
     _cairo_ps_surface_emit_header (surface);
 
     status = _cairo_ps_surface_emit_font_subsets (surface);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP;
 
     status = _cairo_ps_surface_emit_body (surface);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP;
 
     _cairo_ps_surface_emit_footer (surface);
@@ -1362,7 +1362,7 @@ _cairo_ps_surface_end_page (cairo_ps_surface_t *surface)
     cairo_int_status_t status;
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->stream,
@@ -1378,7 +1378,7 @@ _cairo_ps_surface_show_page (void *abstract_surface)
     cairo_int_status_t status;
 
     status = _cairo_ps_surface_end_page (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->stream, "showpage\n");
@@ -1407,7 +1407,7 @@ _cairo_ps_surface_analyze_surface_pattern_transparency (cairo_ps_surface_t
     status = _cairo_surface_acquire_source_image (pattern->surface,
 						  &image,
 						  &image_extra);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (image->base.status)
@@ -1809,7 +1809,7 @@ _cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t    *surface,
 					    background_color,
 					    0, 0,
 					    image->width, image->height);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     status = _cairo_surface_composite (CAIRO_OPERATOR_OVER,
@@ -1821,7 +1821,7 @@ _cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t    *surface,
 				       0, 0,
 				       image->width,
 				       image->height);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     _cairo_pattern_fini (&pattern.base);
@@ -1851,12 +1851,12 @@ _cairo_ps_surface_emit_base85_string (cairo_ps_surface_t    *surface,
 	string_array_stream = _base85_array_stream_create (surface->stream);
 
     status = _cairo_output_stream_get_status (string_array_stream);
-    if (status)
+    if (unlikely (status))
 	return _cairo_output_stream_destroy (string_array_stream);
 
     base85_stream = _cairo_base85_stream_create (string_array_stream);
     status = _cairo_output_stream_get_status (base85_stream);
-    if (status) {
+    if (unlikely (status)) {
 	status2 = _cairo_output_stream_destroy (string_array_stream);
 	return _cairo_output_stream_destroy (base85_stream);
     }
@@ -1918,7 +1918,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
 	status = _cairo_ps_surface_flatten_image_transparency (surface,
 							       image,
 							       &opaque_image);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	use_mask = FALSE;
@@ -2004,7 +2004,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
 						       data_compressed,
 						       data_compressed_size,
 						       TRUE);
-	if (status)
+	if (unlikely (status))
 	    goto bail3;
 
 	_cairo_output_stream_printf (surface->stream,
@@ -2138,7 +2138,7 @@ _cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t    *surface,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (info.num_components != 1 && info.num_components != 3)
@@ -2154,7 +2154,7 @@ _cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t    *surface,
 						       mime_data,
 						       mime_data_length,
 						       TRUE);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->stream,
@@ -2219,7 +2219,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t  *surface,
     cairo_status_t status;
 
     status = _cairo_surface_get_extents (meta_surface, &meta_extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     old_content = surface->content;
@@ -2251,11 +2251,11 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t  *surface,
     status = _cairo_meta_surface_replay_region (meta_surface, &surface->base,
 						CAIRO_META_REGION_NATIVE);
     assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->stream,
@@ -2267,7 +2267,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t  *surface,
     _cairo_pdf_operators_reset (&surface->pdf_operators);
     surface->cairo_to_ps = old_cairo_to_ps;
     status = _cairo_surface_set_clip (&surface->base, old_clip);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
@@ -2337,7 +2337,7 @@ _cairo_ps_surface_acquire_surface (cairo_ps_surface_t      *surface,
 	cairo_rectangle_int_t pattern_extents;
 
 	status = _cairo_surface_get_extents (meta_surface, &pattern_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	*width = pattern_extents.width;
@@ -2346,7 +2346,7 @@ _cairo_ps_surface_acquire_surface (cairo_ps_surface_t      *surface,
 	status = _cairo_surface_acquire_source_image (pattern->surface,
 						      &surface->acquired_image,
 						      &surface->image_extra);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	pad_image = &surface->acquired_image->base;
@@ -2383,7 +2383,7 @@ _cairo_ps_surface_acquire_surface (cairo_ps_surface_t      *surface,
 					       rect.width,
 					       rect.height);
 	    _cairo_pattern_fini (&pad_pattern.base);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 	}
 
@@ -2458,7 +2458,7 @@ _cairo_ps_surface_paint_surface (cairo_ps_surface_t      *surface,
 						extents,
 						&width, &height,
 						&origin_x, &origin_y);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_p2d = pattern->base.matrix;
@@ -2540,7 +2540,7 @@ _cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t      *surface,
 						extents,
 						&pattern_width, &pattern_height,
 						&origin_x, &origin_y);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     switch (pattern->base.extend) {
@@ -2602,7 +2602,7 @@ _cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t      *surface,
     }
     status = _cairo_ps_surface_emit_surface (surface, pattern, op,
 					     pattern_width, pattern_height);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->use_string_datasource = old_use_string_datasource;
@@ -2649,7 +2649,7 @@ _cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t      *surface,
 				 ">>\n");
 
     status = _cairo_surface_get_extents (&surface->base, &surface_extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_p2d = pattern->base.matrix;
@@ -2955,7 +2955,7 @@ _cairo_ps_surface_emit_linear_pattern (cairo_ps_surface_t     *surface,
 
     status = _cairo_ps_surface_emit_pattern_stops (surface,
 						   &pattern->base);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (pattern->base.base.extend == CAIRO_EXTEND_REPEAT ||
@@ -2964,7 +2964,7 @@ _cairo_ps_surface_emit_linear_pattern (cairo_ps_surface_t     *surface,
 							    &pattern->base,
 							    repeat_begin,
 							    repeat_end);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -3042,7 +3042,7 @@ _cairo_ps_surface_emit_radial_pattern (cairo_ps_surface_t     *surface,
     r2 = _cairo_fixed_to_double (pattern->r2);
 
    status = _cairo_ps_surface_emit_pattern_stops (surface, &pattern->base);
-   if (status)
+   if (unlikely (status))
       return status;
 
    _cairo_output_stream_printf (surface->stream,
@@ -3092,7 +3092,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface,
 	    ! _cairo_color_equal (&surface->current_color, &solid->color))
 	{
 	    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern);
@@ -3106,7 +3106,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface,
 
     surface->current_pattern_is_solid_color = FALSE;
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	    return status;
 
     switch (pattern->type) {
@@ -3120,21 +3120,21 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface,
 							 (cairo_surface_pattern_t *) pattern,
 							 extents,
 							 op);
-	if (status)
+	if (unlikely (status))
 	    return status;
 	break;
 
     case CAIRO_PATTERN_TYPE_LINEAR:
 	status = _cairo_ps_surface_emit_linear_pattern (surface,
 					  (cairo_linear_pattern_t *) pattern);
-	if (status)
+	if (unlikely (status))
 	    return status;
 	break;
 
     case CAIRO_PATTERN_TYPE_RADIAL:
 	status = _cairo_ps_surface_emit_radial_pattern (surface,
 					  (cairo_radial_pattern_t *) pattern);
-	if (status)
+	if (unlikely (status))
 	    return status;
 	break;
     }
@@ -3163,7 +3163,7 @@ _cairo_ps_surface_intersect_clip_path (void		   *abstract_surface,
 
     if (path == NULL) {
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (stream, "Q q\n");
@@ -3230,11 +3230,11 @@ _cairo_ps_surface_paint (void			*abstract_surface,
 #endif
 
     status = _cairo_surface_get_extents (&surface->base, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
@@ -3248,7 +3248,7 @@ _cairo_ps_surface_paint (void			*abstract_surface,
 	status = _cairo_ps_surface_paint_surface (surface,
 						 (cairo_surface_pattern_t *) source,
 						  paint_extents, op);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (stream, "Q\n");
@@ -3257,7 +3257,7 @@ _cairo_ps_surface_paint (void			*abstract_surface,
 	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	    return CAIRO_STATUS_SUCCESS;
 
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (stream, "0 0 %d %d rectfill\n",
@@ -3332,7 +3332,7 @@ _cairo_ps_surface_fill (void		*abstract_surface,
 	 source->extend == CAIRO_EXTEND_PAD))
     {
 	status = _cairo_pdf_operators_flush (&surface->pdf_operators);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->stream, "q\n");
@@ -3340,13 +3340,13 @@ _cairo_ps_surface_fill (void		*abstract_surface,
 	status =  _cairo_pdf_operators_clip (&surface->pdf_operators,
 					     path,
 					     fill_rule);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_ps_surface_paint_surface (surface,
 						 (cairo_surface_pattern_t *) source,
 						  extents, op);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->stream, "Q\n");
@@ -3356,7 +3356,7 @@ _cairo_ps_surface_fill (void		*abstract_surface,
 	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	    return CAIRO_STATUS_SUCCESS;
 
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_pdf_operators_fill (&surface->pdf_operators,
@@ -3397,7 +3397,7 @@ _cairo_ps_surface_show_glyphs (void		     *abstract_surface,
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
         return CAIRO_STATUS_SUCCESS;
 
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators,
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index d8771bb..a1b4c22 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -294,7 +294,7 @@ _cairo_sub_font_create (cairo_scaled_font_subsets_t	*parent,
      * Type 3 fonts */
     if (! _cairo_font_face_is_user (scaled_font->font_face)) {
 	status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &subset_glyph);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_hash_table_destroy (sub_font->sub_font_glyphs);
 	    free (sub_font);
 	    return status;
@@ -349,7 +349,7 @@ _cairo_sub_font_glyph_lookup_unicode (cairo_sub_font_glyph_t *sub_font_glyph,
 	status = scaled_font->backend->index_to_ucs4 (scaled_font,
 						      scaled_font_glyph_index,
 						      &unicode);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -466,7 +466,7 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
 	     * except for Type 3 fonts */
 	    if (! _cairo_font_face_is_user (sub_font->scaled_font->font_face)) {
 		status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &tmp_subset_glyph);
-		if (status)
+		if (unlikely (status))
 		    return status;
 	    }
 	}
@@ -477,7 +477,7 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
                                              CAIRO_SCALED_GLYPH_INFO_METRICS,
                                              &scaled_glyph);
 	assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_scaled_font_thaw_cache (sub_font->scaled_font);
 	    return status;
 	}
@@ -495,13 +495,13 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
 	status = _cairo_sub_font_glyph_lookup_unicode (sub_font_glyph,
 						       sub_font->scaled_font,
 						       scaled_font_glyph_index);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_sub_font_glyph_destroy (sub_font_glyph);
 	    return status;
 	}
 
 	status = _cairo_hash_table_insert (sub_font->sub_font_glyphs, &sub_font_glyph->base);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_sub_font_glyph_destroy (sub_font_glyph);
 	    return status;
 	}
@@ -768,7 +768,7 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
 					     subset_glyph->is_composite,
 					     &sub_font);
 
-            if (status) {
+            if (unlikely (status)) {
 		cairo_scaled_font_destroy (unscaled_font);
                 return status;
 	    }
@@ -776,7 +776,7 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
             status = _cairo_hash_table_insert (subsets->unscaled_sub_fonts,
                                                &sub_font->base);
 
-            if (status) {
+            if (unlikely (status)) {
 		_cairo_sub_font_destroy (sub_font);
                 return status;
 	    }
@@ -808,14 +808,14 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
 					     subset_glyph->is_scaled,
 					     subset_glyph->is_composite,
 					     &sub_font);
-            if (status) {
+            if (unlikely (status)) {
 		cairo_scaled_font_destroy (scaled_font);
                 return status;
 	    }
 
             status = _cairo_hash_table_insert (subsets->scaled_sub_fonts,
                                                &sub_font->base);
-            if (status) {
+            if (unlikely (status)) {
 		_cairo_sub_font_destroy (sub_font);
                 return status;
 	    }
@@ -1003,11 +1003,11 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	}
 
 	status = create_string_entry (subset->glyph_names[0], &entry);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_HASH;
 
 	status = _cairo_hash_table_insert (names, &entry->base);
-	if (status) {
+	if (unlikely (status)) {
 	    free (entry);
 	    goto CLEANUP_HASH;
 	}
@@ -1020,7 +1020,7 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	utf16_len = 0;
 	if (utf8 && *utf8) {
 	    status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len);
-	    if (status)
+	    if (unlikely (status))
 		return status; /* FIXME */
 	}
 
@@ -1043,11 +1043,11 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	}
 
 	status = create_string_entry (subset->glyph_names[i], &entry);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_HASH;
 
 	status = _cairo_hash_table_insert (names, &entry->base);
-	if (status) {
+	if (unlikely (status)) {
 	    free (entry);
 	    goto CLEANUP_HASH;
 	}
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 8b74994..76572a5 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -425,7 +425,7 @@ _cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t
     assert (CAIRO_MUTEX_IS_LOCKED (_cairo_scaled_font_map_mutex));
 
     status = scaled_font->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     placeholder_scaled_font = malloc (sizeof (cairo_scaled_font_t));
@@ -439,14 +439,14 @@ _cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t
 				      &scaled_font->ctm,
 				      &scaled_font->options,
 				      NULL);
-    if (status)
+    if (unlikely (status))
 	goto FREE_PLACEHOLDER;
 
     placeholder_scaled_font->placeholder = TRUE;
 
     status = _cairo_hash_table_insert (cairo_scaled_font_map->hash_table,
 				       &placeholder_scaled_font->hash_entry);
-    if (status)
+    if (unlikely (status))
 	goto FINI_PLACEHOLDER;
 
     CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex);
@@ -599,7 +599,7 @@ _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
     cairo_status_t status;
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_scaled_font_init_key (scaled_font, font_face,
@@ -613,7 +613,7 @@ _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
 				  fabs (scaled_font->scale.yx) + fabs (scaled_font->scale.yy));
     scaled_font->scale_inverse = scaled_font->scale;
     status = cairo_matrix_invert (&scaled_font->scale_inverse);
-    if (status) {
+    if (unlikely (status)) {
 	/* If the font scale matrix is rank 0, just using an all-zero inverse matrix
 	 * makes everything work correctly.  This make font size 0 work without
 	 * producing an error.
@@ -697,7 +697,7 @@ _cairo_scaled_font_set_metrics (cairo_scaled_font_t	    *scaled_font,
     status = _cairo_matrix_compute_basis_scale_factors (&scaled_font->font_matrix,
 						  &font_scale_x, &font_scale_y,
 						  1);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /*
@@ -782,7 +782,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	return _cairo_scaled_font_create_in_error (font_face->status);
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
-    if (status)
+    if (unlikely (status))
 	return _cairo_scaled_font_create_in_error (status);
 
     /* Note that degenerate ctm or font_matrix *are* allowed.
@@ -791,7 +791,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     if (font_face->backend->get_implementation != NULL) {
 	/* indirect implementation, lookup the face that is used for the key */
 	status = font_face->backend->get_implementation (font_face, &impl_face);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_scaled_font_create_in_error (status);
     } else
 	impl_face = font_face;
@@ -889,7 +889,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     /* Otherwise create it and insert it into the hash table. */
     status = font_face->backend->scaled_font_create (font_face, font_matrix,
 						     ctm, options, &scaled_font);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_scaled_font_map_unlock ();
 	status = _cairo_font_face_set_error (font_face, status);
 	return _cairo_scaled_font_create_in_error (status);
@@ -905,7 +905,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 
     _cairo_scaled_font_map_unlock ();
 
-    if (status) {
+    if (unlikely (status)) {
 	/* We can't call _cairo_scaled_font_destroy here since it expects
 	 * that the font has already been successfully inserted into the
 	 * hash table. */
@@ -1221,7 +1221,7 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t   *scaled_font,
 					       &glyphs, &num_glyphs,
 					       NULL, NULL,
 					       NULL);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_scaled_font_set_error (scaled_font, status);
 	goto ZERO_EXTENTS;
     }
@@ -1304,7 +1304,7 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t   *scaled_font,
 					     glyphs[i].index,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
-	if (status) {
+	if (unlikely (status)) {
 	    status = _cairo_scaled_font_set_error (scaled_font, status);
 	    goto UNLOCK;
 	}
@@ -1521,7 +1521,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
     cairo_text_cluster_t *orig_clusters;
 
     status = scaled_font->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* A slew of sanity checks */
@@ -1584,7 +1584,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
 
     /* validate input so backend does not have to */
     status = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, &num_chars);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     _cairo_scaled_font_freeze_cache (scaled_font);
@@ -1682,7 +1682,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
 					     (*glyphs)[i].index,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
-	if (status) {
+	if (unlikely (status)) {
 	    goto DONE;
 	}
 
@@ -1693,7 +1693,7 @@ cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t   *scaled_font,
  DONE: /* error that should be logged on scaled_font happened */
     _cairo_scaled_font_thaw_cache (scaled_font);
 
-    if (status) {
+    if (unlikely (status)) {
 	*num_glyphs = 0;
 	if (*glyphs != orig_glyphs) {
 	    cairo_glyph_free (*glyphs);
@@ -1752,7 +1752,7 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t	 *scaled_font,
 					     glyphs[i].index,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	/* XXX glyph images are snapped to pixel locations */
@@ -1771,7 +1771,7 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t	 *scaled_font,
     }
 
     _cairo_scaled_font_thaw_cache (scaled_font);
-    if (status)
+    if (unlikely (status))
 	return _cairo_scaled_font_set_error (scaled_font, status);
 
     if (min.x < max.x && min.y < max.y) {
@@ -1853,7 +1853,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
 					     CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					     &scaled_glyph);
 
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_MASK;
 
 	glyph_surface = scaled_glyph->surface;
@@ -1912,7 +1912,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
 
 	    _cairo_pattern_fini (&mask_pattern.base);
 
-	    if (status) {
+	    if (unlikely (status)) {
 		cairo_surface_destroy (new_mask);
 		goto CLEANUP_MASK;
 	    }
@@ -1940,7 +1940,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t    *scaled_font,
 
 	_cairo_pattern_fini (&glyph_pattern.base);
 
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP_MASK;
     }
 
@@ -2027,29 +2027,29 @@ _add_unit_rectangle_to_path (cairo_path_fixed_t *path, int x, int y)
     status = _cairo_path_fixed_move_to (path,
 					_cairo_fixed_from_int (x),
 					_cairo_fixed_from_int (y));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_path_fixed_rel_line_to (path,
 					    _cairo_fixed_from_int (1),
 					    _cairo_fixed_from_int (0));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_path_fixed_rel_line_to (path,
 					    _cairo_fixed_from_int (0),
 					    _cairo_fixed_from_int (1));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_path_fixed_rel_line_to (path,
 					    _cairo_fixed_from_int (-1),
 					    _cairo_fixed_from_int (0));
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_path_fixed_close_path (path);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -2089,7 +2089,7 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
 	a1_mask = _cairo_image_surface_clone (mask, CAIRO_FORMAT_A1);
 
     status = cairo_surface_status (&a1_mask->base);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&a1_mask->base);
 	return status;
     }
@@ -2104,7 +2104,7 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
 		if (byte & (1 << bit)) {
 		    status = _add_unit_rectangle_to_path (path,
 							  x - xoff, y - yoff);
-		    if (status)
+		    if (unlikely (status))
 			goto BAIL;
 		}
 	    }
@@ -2129,7 +2129,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
     cairo_path_fixed_t *glyph_path;
 
     status = scaled_font->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     closure.path = path;
@@ -2153,7 +2153,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
 						 glyphs[i].index,
 						 CAIRO_SCALED_GLYPH_INFO_SURFACE,
 						 &scaled_glyph);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 
 	    glyph_path = _cairo_path_fixed_create ();
@@ -2163,7 +2163,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
 	    }
 
 	    status = _trace_mask_to_path (scaled_glyph->surface, glyph_path);
-	    if (status) {
+	    if (unlikely (status)) {
 		_cairo_path_fixed_destroy (glyph_path);
 		goto BAIL;
 	    }
@@ -2182,7 +2182,7 @@ _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
 	if (glyph_path != scaled_glyph->path)
 	    _cairo_path_fixed_destroy (glyph_path);
 
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
     }
   BAIL:
@@ -2377,7 +2377,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 	/* ask backend to initialize metrics and shape fields */
 	status = (*scaled_font->backend->
 		  scaled_glyph_init) (scaled_font, scaled_glyph, info);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_scaled_glyph_destroy (scaled_glyph);
 	    goto CLEANUP;
 	}
@@ -2385,7 +2385,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 	/* on success, the cache takes ownership of the scaled_glyph */
 	status = _cairo_cache_insert (scaled_font->glyphs,
 				      &scaled_glyph->cache_entry);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_scaled_glyph_destroy (scaled_glyph);
 	    goto CLEANUP;
 	}
@@ -2410,7 +2410,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
     if (need_info) {
 	status = (*scaled_font->backend->
 		  scaled_glyph_init) (scaled_font, scaled_glyph, need_info);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP;
 
 	/* Don't trust the scaled_glyph_init() return value, the font
@@ -2438,7 +2438,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
     }
 
   CLEANUP:
-    if (status) {
+    if (unlikely (status)) {
 	/* It's not an error for the backend to not support the info we want. */
 	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
 	    status = _cairo_scaled_font_set_error (scaled_font, status);
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index 9118d66..fc3164d 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -335,7 +335,7 @@ _emit_context (cairo_script_surface_t *surface)
 
 	status = _bitmap_next_id (&surface->ctx->surface_id,
 				  &surface->id);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->ctx->stream,
@@ -586,25 +586,25 @@ _emit_stroke_style (cairo_script_surface_t *surface,
     assert (_cairo_script_surface_owns_context (surface));
 
     status = _emit_line_width (surface, style->line_width, force);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_line_cap (surface, style->line_cap);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_line_join (surface, style->line_join);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_miter_limit (surface, style->miter_limit, force);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_dash (surface,
 			 style->dash, style->num_dashes, style->dash_offset,
 			 force);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -750,13 +750,13 @@ _emit_meta_surface_pattern (cairo_script_surface_t *surface,
     cairo_surface_destroy (null_surface);
 
     status = analysis_surface->status;
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_meta_surface_replay (source, analysis_surface);
     _cairo_analysis_surface_get_bounding_box (analysis_surface, &bbox);
     cairo_surface_destroy (analysis_surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     similar = cairo_surface_create_similar (&surface->base,
@@ -767,13 +767,13 @@ _emit_meta_surface_pattern (cairo_script_surface_t *surface,
 	return similar->status;
 
     status = _cairo_meta_surface_replay (source, similar);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (similar);
 	return status;
     }
 
     status = _emit_context (surface);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (similar);
 	return status;
     }
@@ -936,7 +936,7 @@ _emit_png_surface (cairo_script_surface_t *surface,
     base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
     _cairo_output_stream_write (base85_stream, mime_data, mime_data_length);
     status = _cairo_output_stream_destroy (base85_stream);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream,
@@ -979,7 +979,7 @@ _emit_image_surface (cairo_script_surface_t *surface,
 	    status2 = _cairo_output_stream_destroy (base85_stream);
 	    if (status == CAIRO_STATUS_SUCCESS)
 		status = status2;
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_output_stream_puts (surface->ctx->stream,
@@ -1006,7 +1006,7 @@ _emit_image_surface (cairo_script_surface_t *surface,
 	base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
 	_cairo_output_stream_write (base85_stream, mime_data, mime_data_length);
 	status = _cairo_output_stream_destroy (base85_stream);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_puts (surface->ctx->stream,
@@ -1034,7 +1034,7 @@ _emit_image_surface_pattern (cairo_script_surface_t *surface,
 
     /* XXX snapshot-cow */
     status = _cairo_surface_acquire_source_image (source, &image, &image_extra);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_image_surface (surface, image);
@@ -1089,7 +1089,7 @@ _emit_pattern (cairo_script_surface_t *surface,
 	ASSERT_NOT_REACHED;
 	status = CAIRO_INT_STATUS_UNSUPPORTED;
     }
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (! _cairo_matrix_is_identity (&pattern->matrix)) {
@@ -1151,15 +1151,15 @@ _emit_source (cairo_script_surface_t *surface,
     cairo_pattern_destroy (surface->cr.current_source);
     status = _cairo_pattern_create_copy (&surface->cr.current_source,
 					 source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_identity (surface, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_pattern (surface, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream,
@@ -1242,7 +1242,7 @@ _emit_path (cairo_script_surface_t *surface,
 	double y2 = _cairo_fixed_to_double (box.p2.y);
 
 	status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->ctx->stream,
@@ -1252,7 +1252,7 @@ _emit_path (cairo_script_surface_t *surface,
 	cairo_status_t status;
 
 	status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	status = _cairo_path_fixed_interpret (path,
@@ -1262,7 +1262,7 @@ _emit_path (cairo_script_surface_t *surface,
 					      _path_curve_to,
 					      _path_close,
 					      surface->ctx->stream);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -1356,7 +1356,7 @@ _cairo_script_surface_create_similar (void	       *abstract_surface,
 
 	status = _bitmap_next_id (&ctx->surface_id,
 				  &other->id);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_surface_create_in_error (status);
 
 	_cairo_output_stream_printf (ctx->stream,
@@ -1378,7 +1378,7 @@ _cairo_script_surface_create_similar (void	       *abstract_surface,
 
     status = _bitmap_next_id (&ctx->surface_id,
 			      &surface->id);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&surface->base);
 	return _cairo_surface_create_in_error (status);
     }
@@ -1455,7 +1455,7 @@ _cairo_script_surface_copy_page (void *abstract_surface)
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream, "copy_page\n");
@@ -1470,7 +1470,7 @@ _cairo_script_surface_show_page (void *abstract_surface)
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream, "show_page\n");
@@ -1490,7 +1490,7 @@ _cairo_script_surface_intersect_clip_path (void			*abstract_surface,
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (path == NULL) {
@@ -1499,23 +1499,23 @@ _cairo_script_surface_intersect_clip_path (void			*abstract_surface,
     }
 
     status = _emit_identity (surface, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_fill_rule (surface, fill_rule);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_tolerance (surface, tolerance, matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_antialias (surface, antialias);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_path (surface, path);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream, "clip+\n");
@@ -1533,15 +1533,15 @@ _cairo_script_surface_paint (void			*abstract_surface,
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_operator (surface, op);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_source (surface, op, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream,
@@ -1561,19 +1561,19 @@ _cairo_script_surface_mask (void			*abstract_surface,
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_operator (surface, op);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_source (surface, op, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_pattern (surface, mask);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream,
@@ -1599,39 +1599,39 @@ _cairo_script_surface_stroke (void				*abstract_surface,
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_identity (surface, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_path (surface, path);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_source (surface, op, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_matrix (surface, ctm, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_operator (surface, op);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_stroke_style (surface, style, matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_tolerance (surface, tolerance, matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_antialias (surface, antialias);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream, "stroke+\n");
@@ -1654,35 +1654,35 @@ _cairo_script_surface_fill (void			*abstract_surface,
     cairo_status_t status;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_operator (surface, op);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_identity (surface, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_source (surface, op, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_fill_rule (surface, fill_rule);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_tolerance (surface, tolerance, matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_antialias (surface, antialias);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_path (surface, path);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_puts (surface->ctx->stream, "fill+\n");
@@ -1828,7 +1828,7 @@ _emit_type42_font (cairo_script_surface_t *surface,
 
     size = 0;
     status = backend->load_truetype_table (scaled_font, 0, 0, NULL, &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     buf = malloc (size);
@@ -1836,7 +1836,7 @@ _emit_type42_font (cairo_script_surface_t *surface,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     status = backend->load_truetype_table (scaled_font, 0, 0, buf, NULL);
-    if (status) {
+    if (unlikely (status)) {
 	free (buf);
 	return status;
     }
@@ -1898,7 +1898,7 @@ _emit_scaled_font_init (cairo_script_surface_t *surface,
 
     status = _bitmap_next_id (&surface->ctx->font_id,
 			      &font_private->id);
-    if (status) {
+    if (unlikely (status)) {
 	free (font_private);
 	return status;
     }
@@ -1907,7 +1907,7 @@ _emit_scaled_font_init (cairo_script_surface_t *surface,
     scaled_font->surface_backend = &_cairo_script_surface_backend;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_type42_font (surface, scaled_font);
@@ -1943,7 +1943,7 @@ _emit_scaled_font (cairo_script_surface_t *surface,
 
     cairo_scaled_font_get_ctm (scaled_font, &matrix);
     status = _emit_matrix (surface, &matrix, &matrix_updated);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (! matrix_updated && surface->cr.current_scaled_font == scaled_font)
@@ -1951,12 +1951,12 @@ _emit_scaled_font (cairo_script_surface_t *surface,
 
     cairo_scaled_font_get_font_matrix (scaled_font, &matrix);
     status = _emit_font_matrix (surface, &matrix);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cairo_scaled_font_get_font_options (scaled_font, &options);
     status = _emit_font_options (surface, &options);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     surface->cr.current_scaled_font = scaled_font;
@@ -1967,11 +1967,11 @@ _emit_scaled_font (cairo_script_surface_t *surface,
     font_private = scaled_font->surface_private;
     if (font_private == NULL) {
 	status = _emit_scaled_font_init (surface, scaled_font);
-	if (status)
+	if (unlikely (status))
 	    return status;
     } else {
 	status = _emit_context (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->ctx->stream,
@@ -2059,7 +2059,7 @@ _emit_scaled_glyph_bitmap (cairo_script_surface_t *surface,
 				 scaled_glyph->fs_metrics.y_bearing);
 
     status = _emit_image_surface (surface, scaled_glyph->surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (! _cairo_matrix_is_identity (&scaled_font->font_matrix)) {
@@ -2121,7 +2121,7 @@ _emit_scaled_glyphs (cairo_script_surface_t *surface,
 					     glyphs[n].index,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	if (scaled_glyph->surface_private != NULL)
@@ -2137,7 +2137,7 @@ _emit_scaled_glyphs (cairo_script_surface_t *surface,
 	if (status == CAIRO_STATUS_SUCCESS) {
 	    if (! have_glyph_prologue) {
 		status = _emit_scaled_glyph_prologue (surface, scaled_font);
-		if (status)
+		if (unlikely (status))
 		    break;
 
 		have_glyph_prologue = TRUE;
@@ -2146,7 +2146,7 @@ _emit_scaled_glyphs (cairo_script_surface_t *surface,
 	    status = _emit_scaled_glyph_vector (surface,
 						scaled_font,
 						scaled_glyph);
-	    if (status)
+	    if (unlikely (status))
 		break;
 
 	    continue;
@@ -2162,7 +2162,7 @@ _emit_scaled_glyphs (cairo_script_surface_t *surface,
 	if (status == CAIRO_STATUS_SUCCESS) {
 	    if (! have_glyph_prologue) {
 		status = _emit_scaled_glyph_prologue (surface, scaled_font);
-		if (status)
+		if (unlikely (status))
 		    break;
 
 		have_glyph_prologue = TRUE;
@@ -2171,7 +2171,7 @@ _emit_scaled_glyphs (cairo_script_surface_t *surface,
 	    status = _emit_scaled_glyph_bitmap (surface,
 						scaled_font,
 						scaled_glyph);
-	    if (status)
+	    if (unlikely (status))
 		break;
 
 	    continue;
@@ -2210,23 +2210,23 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
     cairo_output_stream_t *base85_stream = NULL;
 
     status = _emit_context (surface);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_operator (surface, op);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_source (surface, op, source);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_scaled_font (surface, scaled_font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _emit_scaled_glyphs (surface, scaled_font, glyphs, num_glyphs);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* (utf8) [cx cy [glyphs]] [clusters] backward show_text_glyphs */
@@ -2264,7 +2264,7 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
 						 glyphs[n].index,
 						 CAIRO_SCALED_GLYPH_INFO_METRICS,
 						 &scaled_glyph);
-	    if (status) {
+	    if (unlikely (status)) {
 		_cairo_scaled_font_thaw_cache (scaled_font);
 		return status;
 	    }
@@ -2284,7 +2284,7 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
 					     glyphs[n].index,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
-	if (status)
+	if (unlikely (status))
 	    break;
 
 	if (fabs (glyphs[n].x - x) > 1e-5 || fabs (glyphs[n].y - y) > 1e-5) {
@@ -2295,7 +2295,7 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
 	    iy -= scaled_font->font_matrix.y0;
 	    if (base85_stream != NULL) {
 		status = _cairo_output_stream_destroy (base85_stream);
-		if (status) {
+		if (unlikely (status)) {
 		    base85_stream = NULL;
 		    break;
 		}
@@ -2345,7 +2345,7 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
     } else {
 	_cairo_output_stream_puts (surface->ctx->stream, " ]");
     }
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (utf8 != NULL && clusters != NULL) {
@@ -2378,7 +2378,7 @@ _cairo_script_surface_show_text_glyphs (void			    *abstract_surface,
 		_cairo_output_stream_write (base85_stream, c, 2);
 	    }
 	    status = _cairo_output_stream_destroy (base85_stream);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
 
diff --git a/src/cairo-sdl-surface.c b/src/cairo-sdl-surface.c
index 18f13ea..800ad83 100644
--- a/src/cairo-sdl-surface.c
+++ b/src/cairo-sdl-surface.c
@@ -240,7 +240,7 @@ _cairo_sdl_surface_composite (cairo_operator_t		 op,
 					     src_x, src_y, width, height,
 					     (cairo_surface_t **) &src,
 					     &src_attr);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     is_integer_translation =
@@ -324,7 +324,7 @@ _cairo_sdl_surface_flush (void                  *abstract_surface)
 
     n_boxes = 0;
     status = _cairo_region_get_boxes (&surface->update, &n_boxes, &boxes);
-    if (status)
+    if (unlikely (status))
 	return status;
     if (n_boxes == 0)
 	return CAIRO_STATUS_SUCCESS;
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index 2dcaa58..bb80538 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -79,7 +79,7 @@ _fallback_init (fallback_state_t *state,
     status = _cairo_surface_acquire_dest_image (dst, &state->extents,
 						&state->image, &state->image_rect,
 						&state->image_extra);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* XXX: This NULL value tucked away in state->image is a rather
@@ -131,7 +131,7 @@ _create_composite_mask_pattern (cairo_surface_pattern_t       *mask_pattern,
 			   NULL, mask,
 			   extents->x, extents->y,
 			   extents);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     if (clip && clip->surface)
@@ -139,7 +139,7 @@ _create_composite_mask_pattern (cairo_surface_pattern_t       *mask_pattern,
 						 mask,
 						 extents->x, extents->y,
 						 extents);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     _cairo_pattern_init_for_surface (mask_pattern, mask);
@@ -169,7 +169,7 @@ _clip_and_composite_with_mask (cairo_clip_t                  *clip,
 					     clip,
 					     draw_func, draw_closure,
 					     dst, extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_surface_composite (op,
@@ -226,14 +226,14 @@ _clip_and_composite_combine (cairo_clip_t                  *clip,
 
     _cairo_pattern_fini (&dst_pattern.base);
 
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     status = (*draw_func) (draw_closure, op,
 			   src, intermediate,
 			   extents->x, extents->y,
 			   extents);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     /* Combine that with the clip
@@ -242,7 +242,7 @@ _clip_and_composite_combine (cairo_clip_t                  *clip,
 					     intermediate,
 					     extents->x, extents->y,
 					     extents);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     /* Punch the clip out of the destination
@@ -251,7 +251,7 @@ _clip_and_composite_combine (cairo_clip_t                  *clip,
 					     dst,
 					     0, 0,
 					     extents);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SURFACE;
 
     /* Now add the two results together
@@ -293,7 +293,7 @@ _clip_and_composite_source (cairo_clip_t                  *clip,
 					     clip,
 					     draw_func, draw_closure,
 					     dst, extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Compute dest' = dest OUT (mask IN clip)
@@ -305,7 +305,7 @@ _clip_and_composite_source (cairo_clip_t                  *clip,
 				       extents->x,     extents->y,
 				       extents->width, extents->height);
 
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_MASK_PATTERN;
 
     /* Now compute (src IN (mask IN clip)) ADD dest'
@@ -439,7 +439,7 @@ _composite_trap_region (cairo_clip_t            *clip,
 	status = _cairo_surface_set_clip_region (dst,
 						 trap_region,
 						 clip_serial);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -531,7 +531,7 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src,
         return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_surface_get_extents (dst, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = _cairo_traps_extract_region (traps, &trap_region);
@@ -548,7 +548,7 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src,
 
         if (has_trap_region) {
             status = _cairo_clip_intersect_to_region (clip, &trap_region);
-            if (status)
+            if (unlikely (status))
                 goto out;
 
             _cairo_region_get_extents (&trap_region, &trap_extents);
@@ -564,7 +564,7 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src,
 	}
 
         status = _cairo_clip_intersect_to_rectangle (clip, &extents);
-        if (status)
+        if (unlikely (status))
             goto out;
     } else {
         cairo_surface_t *clip_surface = clip ? clip->surface : NULL;
@@ -579,13 +579,13 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src,
             has_clear_region = TRUE;
             status = _cairo_clip_intersect_to_region (clip, &clear_region);
 
-            if (status)
+            if (unlikely (status))
                 goto out;
 
             _cairo_region_get_extents (&clear_region, &extents);
 
             status = _cairo_region_subtract (&clear_region, &clear_region, &trap_region);
-            if (status)
+            if (unlikely (status))
                 goto out;
 
             if (!_cairo_region_not_empty (&clear_region)) {
@@ -597,7 +597,7 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src,
         }
     }
 
-    if (status)
+    if (unlikely (status))
         goto out;
 
     if (has_trap_region) {
@@ -681,14 +681,14 @@ _cairo_surface_fallback_paint (cairo_surface_t		*surface,
     cairo_traps_t traps;
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (_cairo_operator_bounded_by_source (op)) {
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &source_extents))
@@ -696,7 +696,7 @@ _cairo_surface_fallback_paint (cairo_surface_t		*surface,
     }
 
     status = _cairo_clip_intersect_to_rectangle (surface->clip, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_box_from_rectangle (&box, &extents);
@@ -752,12 +752,12 @@ _cairo_surface_fallback_mask (cairo_surface_t		*surface,
     cairo_rectangle_int_t extents, source_extents, mask_extents;
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (_cairo_operator_bounded_by_source (op)) {
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &source_extents))
@@ -766,7 +766,7 @@ _cairo_surface_fallback_mask (cairo_surface_t		*surface,
 
     if (_cairo_operator_bounded_by_mask (op)) {
 	status = _cairo_pattern_get_extents (mask, &mask_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &mask_extents))
@@ -774,7 +774,7 @@ _cairo_surface_fallback_mask (cairo_surface_t		*surface,
     }
 
     status = _cairo_clip_intersect_to_rectangle (surface->clip, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _clip_and_composite (surface->clip, op,
@@ -804,13 +804,13 @@ _cairo_surface_fallback_stroke (cairo_surface_t		*surface,
     cairo_rectangle_int_t extents;
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (_cairo_operator_bounded_by_source (op)) {
 	cairo_rectangle_int_t source_extents;
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &source_extents))
@@ -818,7 +818,7 @@ _cairo_surface_fallback_stroke (cairo_surface_t		*surface,
     }
 
     status = _cairo_clip_intersect_to_rectangle (surface->clip, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (extents.width == 0 || extents.height == 0)
@@ -834,7 +834,7 @@ _cairo_surface_fallback_stroke (cairo_surface_t		*surface,
 						ctm, ctm_inverse,
 						tolerance,
 						&traps);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     status = _clip_and_composite_trapezoids (source,
@@ -865,14 +865,14 @@ _cairo_surface_fallback_fill (cairo_surface_t		*surface,
     cairo_rectangle_int_t extents;
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (_cairo_operator_bounded_by_source (op)) {
 	cairo_rectangle_int_t source_extents;
 
 	status = _cairo_pattern_get_extents (source, &source_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &source_extents))
@@ -880,7 +880,7 @@ _cairo_surface_fallback_fill (cairo_surface_t		*surface,
     }
 
     status = _cairo_clip_intersect_to_rectangle (surface->clip, &extents);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (extents.width == 0 || extents.height == 0)
@@ -895,7 +895,7 @@ _cairo_surface_fallback_fill (cairo_surface_t		*surface,
 					      fill_rule,
 					      tolerance,
 					      &traps);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_traps_fini (&traps);
 	return status;
     }
@@ -992,7 +992,7 @@ _cairo_surface_fallback_show_glyphs (cairo_surface_t		*surface,
     cairo_show_glyphs_info_t glyph_info;
 
     status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (_cairo_operator_bounded_by_mask (op)) {
@@ -1002,7 +1002,7 @@ _cairo_surface_fallback_show_glyphs (cairo_surface_t		*surface,
 							  glyphs,
 							  num_glyphs,
 							  &glyph_extents);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (! _cairo_rectangle_intersect (&extents, &glyph_extents))
@@ -1010,7 +1010,7 @@ _cairo_surface_fallback_show_glyphs (cairo_surface_t		*surface,
     }
 
     status = _cairo_clip_intersect_to_rectangle (surface->clip, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     glyph_info.font = scaled_font;
@@ -1045,7 +1045,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
 
     status = _cairo_surface_acquire_source_image (surface,
 						  &image, &image_extra);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_create_in_error (status);
 
     snapshot = cairo_image_surface_create (image->format,
@@ -1073,7 +1073,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
     _cairo_surface_release_source_image (surface,
 					 image, image_extra);
 
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (snapshot);
 	return _cairo_surface_create_in_error (status);
     }
@@ -1083,7 +1083,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
 
     for (mime_type = mime_types; *mime_type; mime_type++) {
 	status = _cairo_surface_copy_mime_data (snapshot, surface, *mime_type);
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_surface_destroy (snapshot);
 	    return _cairo_surface_create_in_error (status);
 	}
@@ -1112,7 +1112,7 @@ _cairo_surface_fallback_composite (cairo_operator_t		 op,
     cairo_status_t status;
 
     status = _fallback_init (&state, dst, dst_x, dst_y, width, height);
-    if (status) {
+    if (unlikely (status)) {
 	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	    return CAIRO_STATUS_SUCCESS;
 	return status;
@@ -1173,7 +1173,7 @@ _cairo_surface_fallback_fill_rectangles (cairo_surface_t         *surface,
     }
 
     status = _fallback_init (&state, surface, x1, y1, x2 - x1, y2 - y1);
-    if (status) {
+    if (unlikely (status)) {
 	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	    return CAIRO_STATUS_SUCCESS;
 	return status;
@@ -1229,7 +1229,7 @@ _cairo_surface_fallback_composite_trapezoids (cairo_operator_t		op,
     cairo_status_t status;
 
     status = _fallback_init (&state, dst, dst_x, dst_y, width, height);
-    if (status) {
+    if (unlikely (status)) {
 	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
 	    return CAIRO_STATUS_SUCCESS;
 	return status;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 4c10f95..a6c97f2 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -322,7 +322,7 @@ _cairo_surface_create_similar_solid (cairo_surface_t	 *other,
 
     _cairo_pattern_fini (&solid_pattern.base);
 
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (surface);
 	return _cairo_surface_create_in_error (status);
     }
@@ -455,7 +455,7 @@ _cairo_surface_reset (cairo_surface_t *surface)
 
     if (surface->backend->reset != NULL) {
 	cairo_status_t status = surface->backend->reset (surface);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_surface_set_error (surface, status);
     }
 
@@ -523,7 +523,7 @@ cairo_surface_finish (cairo_surface_t *surface)
     /* call finish even if in error mode */
     if (surface->backend->finish) {
 	status = surface->backend->finish (surface);
-	if (status)
+	if (unlikely (status))
 	    status = _cairo_surface_set_error (surface, status);
     }
 
@@ -608,7 +608,7 @@ cairo_surface_get_mime_data (cairo_surface_t		*surface,
 	return;
 
     status = _cairo_intern_string (&mime_type, -1);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
@@ -672,7 +672,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 	return surface->status;
 
     status = _cairo_intern_string (&mime_type, -1);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     if (data != NULL) {
@@ -693,7 +693,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 					      (cairo_user_data_key_t *) mime_type,
 					      mime_data,
 					      _cairo_mime_data_destroy);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -715,7 +715,7 @@ _cairo_surface_copy_mime_data (cairo_surface_t *dst,
 	return _cairo_surface_set_error (dst, src->status);
 
     status = _cairo_intern_string (&mime_type, -1);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (dst, status);
 
     mime_data = _cairo_user_data_array_get_data (&src->user_data,
@@ -729,7 +729,7 @@ _cairo_surface_copy_mime_data (cairo_surface_t *dst,
 					      (cairo_user_data_key_t *) mime_type,
 					      mime_data,
 					      _cairo_mime_data_destroy);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_mime_data_destroy (mime_data);
 	return _cairo_surface_set_error (dst, status);
     }
@@ -839,7 +839,7 @@ cairo_surface_flush (cairo_surface_t *surface)
 
     if (surface->backend->flush) {
 	status = surface->backend->flush (surface);
-	if (status)
+	if (unlikely (status))
 	    status = _cairo_surface_set_error (surface, status);
     }
 }
@@ -917,7 +917,7 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
                                                          y + surface->device_transform.y0,
 							 width, height);
 
-	if (status)
+	if (unlikely (status))
 	    status = _cairo_surface_set_error (surface, status);
     }
 }
@@ -1355,7 +1355,7 @@ _cairo_surface_clone_similar (cairo_surface_t  *surface,
 						   clone_out);
 
     /* We should never get UNSUPPORTED here, so if we have an error, bail. */
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Update the clone's device_transform (which the underlying surface
@@ -1562,7 +1562,7 @@ _cairo_surface_fill_region (cairo_surface_t	   *surface,
     if (num_boxes > 1) {
 	num_boxes = sizeof (stack_rects) / sizeof (cairo_box_int_t);
 	status = _cairo_region_get_boxes (region, &num_boxes, &boxes);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (num_boxes > ARRAY_LENGTH (stack_rects)) {
@@ -1661,7 +1661,7 @@ _cairo_surface_paint (cairo_surface_t	*surface,
     status = _cairo_surface_copy_pattern_for_destination (&source,
 							  surface,
 							  &dev_source.base);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     if (surface->backend->paint) {
@@ -1698,13 +1698,13 @@ _cairo_surface_mask (cairo_surface_t		*surface,
     status = _cairo_surface_copy_pattern_for_destination (&source,
 							  surface,
 							  &dev_source.base);
-    if (status)
+    if (unlikely (status))
 	goto FINISH;
 
     status = _cairo_surface_copy_pattern_for_destination (&mask,
 							  surface,
 							  &dev_mask.base);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_SOURCE;
 
     if (surface->backend->mask) {
@@ -1757,13 +1757,13 @@ _cairo_surface_fill_stroke (cairo_surface_t	    *surface,
 	status = _cairo_surface_copy_pattern_for_destination (&stroke_source,
 							      surface,
 							      &dev_stroke_source.base);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_surface_set_error (surface, status);
 
 	status = _cairo_surface_copy_pattern_for_destination (&fill_source,
 							      surface,
 							      &dev_fill_source.base);
-	if (status) {
+	if (unlikely (status)) {
 	    if (stroke_source == &dev_stroke_source.base)
 		_cairo_pattern_fini (&dev_stroke_source.base);
 
@@ -1792,13 +1792,13 @@ _cairo_surface_fill_stroke (cairo_surface_t	    *surface,
 
     status = _cairo_surface_fill (surface, fill_op, fill_source, path,
 				  fill_rule, fill_tolerance, fill_antialias, NULL);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     status = _cairo_surface_stroke (surface, stroke_op, stroke_source, path,
 				    stroke_style, stroke_ctm, stroke_ctm_inverse,
 				    stroke_tolerance, stroke_antialias, NULL);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -1831,7 +1831,7 @@ _cairo_surface_stroke (cairo_surface_t		*surface,
     status = _cairo_surface_copy_pattern_for_destination (&source,
 							  surface,
 							  &dev_source.base);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     if (surface->backend->stroke) {
@@ -1880,7 +1880,7 @@ _cairo_surface_fill (cairo_surface_t	*surface,
     status = _cairo_surface_copy_pattern_for_destination (&source,
 							  surface,
 							  &dev_source.base);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     if (surface->backend->fill) {
@@ -2097,13 +2097,13 @@ _cairo_surface_reset_clip (cairo_surface_t *surface)
 							CAIRO_FILL_RULE_WINDING,
 							0,
 							CAIRO_ANTIALIAS_DEFAULT);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_surface_set_error (surface, status);
     }
 
     if (surface->backend->set_clip_region != NULL) {
 	status = surface->backend->set_clip_region (surface, NULL);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_surface_set_error (surface, status);
     }
 
@@ -2181,7 +2181,7 @@ _cairo_surface_set_clip_path_recursive (cairo_surface_t *surface,
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_surface_set_clip_path_recursive (surface, clip_path->prev);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return _cairo_surface_intersect_clip_path (surface,
@@ -2220,11 +2220,11 @@ _cairo_surface_set_clip_path (cairo_surface_t	*surface,
 						    CAIRO_FILL_RULE_WINDING,
 						    0,
 						    CAIRO_ANTIALIAS_DEFAULT);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     status = _cairo_surface_set_clip_path_recursive (surface, clip_path);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     surface->current_clip_serial = serial;
@@ -2458,7 +2458,7 @@ _cairo_surface_show_text_glyphs (cairo_surface_t	    *surface,
     status = _cairo_surface_copy_pattern_for_destination (&source,
 						          surface,
 							  &dev_source.base);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_set_error (surface, status);
 
     if (_cairo_surface_has_device_transform (surface) &&
@@ -2477,7 +2477,7 @@ _cairo_surface_show_text_glyphs (cairo_surface_t	    *surface,
 						    &font_options);
     }
     status = cairo_scaled_font_status (dev_scaled_font);
-    if (status) {
+    if (unlikely (status)) {
 	if (source == &dev_source.base)
 	    _cairo_pattern_fini (&dev_source.base);
 
@@ -2644,7 +2644,7 @@ _cairo_surface_composite_fixup_unbounded_internal (cairo_surface_t         *dst,
     status = _cairo_region_subtract (&clear_region,
 				     &clear_region,
 				     &drawn_region);
-    if (status)
+    if (unlikely (status))
         goto CLEANUP_REGIONS;
 
   EMPTY:
@@ -2833,7 +2833,7 @@ _cairo_surface_copy_pattern_for_destination (const cairo_pattern_t **pattern,
 	return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_pattern_init_copy (pattern_copy, *pattern);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_pattern_transform (pattern_copy,
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index ab2e4b9..35e256f 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -285,7 +285,7 @@ cairo_svg_surface_restrict_to_version (cairo_surface_t 		*abstract_surface,
     cairo_status_t status;
 
     status = _extract_svg_surface (abstract_surface, &surface);
-    if (status) {
+    if (unlikely (status)) {
 	status = _cairo_surface_set_error (abstract_surface, status);
 	return;
     }
@@ -366,7 +366,7 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t	*document,
 
     surface->xml_node = _cairo_memory_stream_create ();
     status = _cairo_output_stream_get_status (surface->xml_node);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP;
 
     _cairo_array_init (&surface->page_set, sizeof (cairo_svg_page_t));
@@ -378,7 +378,7 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t	*document,
 				     "fill:rgb(0,0,0);\"/>\n",
 				     width, height);
 	status = _cairo_output_stream_get_status (surface->xml_node);
-	if (status)
+	if (unlikely (status))
 	    goto CLEANUP;
     }
 
@@ -421,7 +421,7 @@ _cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t	*stream,
     status = _cairo_svg_document_create (stream,
 	                                 width, height, version,
 					 &document);
-    if (status) {
+    if (unlikely (status)) {
 	surface =  _cairo_surface_create_in_error (status);
 	/* consume the output stream on behalf of caller */
 	status = _cairo_output_stream_destroy (stream);
@@ -614,7 +614,7 @@ _cairo_svg_surface_emit_path (cairo_output_stream_t *output,
 					  _cairo_svg_path_curve_to,
 					  _cairo_svg_path_close_path,
 					  &info);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (output, "\"");
@@ -635,14 +635,14 @@ _cairo_svg_document_emit_outline_glyph_data (cairo_svg_document_t	*document,
 					 CAIRO_SCALED_GLYPH_INFO_METRICS|
 					 CAIRO_SCALED_GLYPH_INFO_PATH,
 					 &scaled_glyph);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (document->xml_node_glyphs,
 				 "<path style=\"stroke:none;\" ");
 
     status = _cairo_svg_surface_emit_path (document->xml_node_glyphs, scaled_glyph->path, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (document->xml_node_glyphs,
@@ -668,7 +668,7 @@ _cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t	*document,
 					 CAIRO_SCALED_GLYPH_INFO_METRICS|
 					 CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					 &scaled_glyph);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     image = scaled_glyph->surface;
@@ -724,7 +724,7 @@ _cairo_svg_document_emit_glyph (cairo_svg_document_t	*document,
 	status = _cairo_svg_document_emit_bitmap_glyph_data (document,
 							     scaled_font,
 							     scaled_font_glyph_index);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (document->xml_node_glyphs, "</symbol>\n");
@@ -746,7 +746,7 @@ _cairo_svg_document_emit_font_subset (cairo_scaled_font_subset_t	*font_subset,
 					         font_subset->scaled_font,
 					         font_subset->glyphs[i],
 					         font_subset->font_id, i);
-	if (status)
+	if (unlikely (status))
 	    break;
     }
     _cairo_scaled_font_thaw_cache (font_subset->scaled_font);
@@ -762,7 +762,7 @@ _cairo_svg_document_emit_font_subsets (cairo_svg_document_t *document)
     status = _cairo_scaled_font_subsets_foreach_scaled (document->font_subsets,
                                                         _cairo_svg_document_emit_font_subset,
                                                         document);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     status = _cairo_scaled_font_subsets_foreach_user (document->font_subsets,
@@ -992,7 +992,7 @@ _cairo_surface_base64_encode_jpeg (cairo_surface_t       *surface,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     status = _cairo_image_info_get_jpeg_info (&image_info, mime_data, mime_data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (output, "data:image/jpeg;base64,");
@@ -1002,7 +1002,7 @@ _cairo_surface_base64_encode_jpeg (cairo_surface_t       *surface,
     info.trailing = 0;
 
     status = base64_write_func (&info, mime_data, mime_data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (info.in_mem > 0) {
@@ -1036,7 +1036,7 @@ _cairo_surface_base64_encode_png (cairo_surface_t       *surface,
     info.trailing = 0;
 
     status = base64_write_func (&info, mime_data, mime_data_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (info.in_mem > 0) {
@@ -1073,7 +1073,7 @@ _cairo_surface_base64_encode (cairo_surface_t       *surface,
     status = cairo_surface_write_to_png_stream (surface, base64_write_func,
 						(void *) &info);
 
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (info.in_mem > 0) {
@@ -1126,7 +1126,7 @@ _cairo_svg_surface_emit_composite_image_pattern (cairo_output_stream_t   *output
     cairo_matrix_t p2u;
 
     status = _cairo_surface_get_extents (pattern->surface, &extents);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     p2u = pattern->base.matrix;
@@ -1214,7 +1214,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document,
 					   document->owner->y_fallback_resolution);
 
     status = _cairo_meta_surface_replay (&meta->base, paginated_surface);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&meta->base);
 	cairo_surface_destroy (paginated_surface);
 	return status;
@@ -1222,7 +1222,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document,
 
     cairo_surface_show_page (paginated_surface);
     status = cairo_surface_status (paginated_surface);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&meta->base);
 	cairo_surface_destroy (paginated_surface);
 	return status;
@@ -1231,7 +1231,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document,
     new_snapshot.meta = meta;
     new_snapshot.id = svg_surface->id;
     status = _cairo_array_append (&document->meta_snapshots, &new_snapshot);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_surface_destroy (&meta->base);
 	cairo_surface_destroy (paginated_surface);
 	return status;
@@ -1321,7 +1321,7 @@ _cairo_svg_surface_emit_composite_meta_pattern (cairo_output_stream_t	*output,
     meta_surface = (cairo_meta_surface_t *) pattern->surface;
 
     status = _cairo_svg_surface_emit_meta_surface (document, meta_surface, &id);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     if (pattern_id != invalid_pattern_id) {
@@ -1407,7 +1407,7 @@ _cairo_svg_surface_emit_surface_pattern (cairo_svg_surface_t	 *surface,
     status = _cairo_svg_surface_emit_composite_pattern (document->xml_node_defs,
 	                                                surface, CAIRO_OPERATOR_SOURCE, pattern,
 							pattern_id, parent_matrix, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (style,
@@ -1634,7 +1634,7 @@ _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t    *surface,
     status = _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs,
 	                                            &pattern->base, 0.0,
 						    FALSE, FALSE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (document->xml_node_defs,
@@ -1812,7 +1812,7 @@ _cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t    *surface,
 		                                        &pattern->base, offset,
 							reverse_stops,
 							emulate_reflect);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	if (pattern->base.base.extend == CAIRO_EXTEND_NONE)
@@ -1927,7 +1927,7 @@ _cairo_svg_surface_emit_stroke_style (cairo_output_stream_t	    *output,
 				 line_join);
 
      status = _cairo_svg_surface_emit_pattern (surface, source, output, TRUE, parent_matrix);
-     if (status)
+     if (unlikely (status))
 	 return status;
 
      _cairo_svg_surface_emit_operator_for_style (output, surface, op);
@@ -1979,18 +1979,18 @@ _cairo_svg_surface_fill_stroke (void			*abstract_surface,
     _cairo_output_stream_printf (surface->xml_node, "<path style=\"");
     status = _cairo_svg_surface_emit_fill_style (surface->xml_node, surface, fill_op,
 						 fill_source, fill_rule, stroke_ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_svg_surface_emit_stroke_style (surface->xml_node, surface, stroke_op,
 						   stroke_source, stroke_style, stroke_ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->xml_node, "\" ");
 
     status = _cairo_svg_surface_emit_path (surface->xml_node, path, stroke_ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_svg_surface_emit_transform (surface->xml_node, " transform", stroke_ctm, NULL);
@@ -2019,13 +2019,13 @@ _cairo_svg_surface_fill (void			*abstract_surface,
 
     _cairo_output_stream_printf (surface->xml_node, "<path style=\" stroke:none;");
     status = _cairo_svg_surface_emit_fill_style (surface->xml_node, surface, op, source, fill_rule, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->xml_node, "\" ");
 
     status = _cairo_svg_surface_emit_path (surface->xml_node, path, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->xml_node, "/>\n");
@@ -2079,7 +2079,7 @@ _cairo_svg_surface_emit_paint (cairo_output_stream_t *output,
 				 surface->width, surface->height);
     _cairo_svg_surface_emit_operator_for_style (output, surface, op);
     status = _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (output, "stroke:none;\"");
@@ -2116,7 +2116,7 @@ _cairo_svg_surface_paint (void		    *abstract_surface,
      * and an optimization in meta surface. */
     if (surface->clip_level == 0 && op == CAIRO_OPERATOR_CLEAR) {
 	status = _cairo_output_stream_destroy (surface->xml_node);
-	if (status) {
+	if (unlikely (status)) {
 	    surface->xml_node = NULL;
 	    return status;
 	}
@@ -2204,7 +2204,7 @@ _cairo_svg_surface_mask (void		    *abstract_surface,
 				 mask_id,
 				 discard_filter ? "" : "  <g filter=\"url(#alpha)\">\n");
     status = _cairo_svg_surface_emit_paint (mask_stream, surface, CAIRO_OPERATOR_OVER, mask, source, NULL);
-    if (status) {
+    if (unlikely (status)) {
 	cairo_status_t ignore = _cairo_output_stream_destroy (mask_stream);
 	return status;
 	(void) ignore;
@@ -2217,13 +2217,13 @@ _cairo_svg_surface_mask (void		    *abstract_surface,
     _cairo_memory_stream_copy (mask_stream, document->xml_node_defs);
 
     status = _cairo_output_stream_destroy (mask_stream);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     snprintf (buffer, sizeof buffer, "mask=\"url(#mask%d)\"",
 	      mask_id);
     status = _cairo_svg_surface_emit_paint (surface->xml_node, surface, op, source, 0, buffer);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -2252,13 +2252,13 @@ _cairo_svg_surface_stroke (void			*abstract_dst,
     _cairo_output_stream_printf (surface->xml_node, "<path style=\"fill:none;");
     status = _cairo_svg_surface_emit_stroke_style (surface->xml_node, surface, op,
 						   source, stroke_style, ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (surface->xml_node, "\" ");
 
     status = _cairo_svg_surface_emit_path (surface->xml_node, path, ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_svg_surface_emit_transform (surface->xml_node, " transform", ctm, NULL);
@@ -2301,7 +2301,7 @@ _cairo_svg_surface_show_glyphs (void			*abstract_surface,
     _cairo_output_stream_printf (surface->xml_node, "<g style=\"");
     status = _cairo_svg_surface_emit_pattern (surface, pattern,
 	                                      surface->xml_node, FALSE, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_svg_surface_emit_operator_for_style (surface->xml_node, surface, op);
@@ -2321,7 +2321,7 @@ _cairo_svg_surface_show_glyphs (void			*abstract_surface,
 	    goto FALLBACK;
 	}
 
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	_cairo_output_stream_printf (surface->xml_node,
@@ -2341,7 +2341,7 @@ FALLBACK:
 
     status = _cairo_scaled_font_glyph_path (scaled_font,(cairo_glyph_t *) glyphs, num_glyphs, &path);
 
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_path_fixed_fini (&path);
 	return status;
     }
@@ -2379,7 +2379,7 @@ _cairo_svg_surface_intersect_clip_path (void			*dst,
 				 "  <path ",
 				 document->clip_id);
     status = _cairo_svg_surface_emit_path (document->xml_node_defs, path, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_printf (document->xml_node_defs,
@@ -2485,12 +2485,12 @@ _cairo_svg_document_create (cairo_output_stream_t	 *output_stream,
 
     document->xml_node_defs = _cairo_memory_stream_create ();
     status = _cairo_output_stream_get_status (document->xml_node_defs);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_NODE_DEFS;
 
     document->xml_node_glyphs = _cairo_memory_stream_create ();
     status = _cairo_output_stream_get_status (document->xml_node_glyphs);
-    if (status)
+    if (unlikely (status))
 	goto CLEANUP_NODE_GLYPHS;
 
     document->alpha_filter = FALSE;
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 4fa3656..a871702 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -666,7 +666,7 @@ _cairo_traps_extract_region (const cairo_traps_t  *traps,
     if (boxes != stack_boxes)
 	free (boxes);
 
-    if (status)
+    if (unlikely (status))
 	_cairo_region_fini (region);
 
     return status;
@@ -705,15 +705,15 @@ _cairo_traps_path (const cairo_traps_t *traps,
 	_sanitize_trap (&trap);
 
 	status = _cairo_path_fixed_move_to (path, trap.left.p1.x, trap.top);
-	if (status) return status;
+	if (unlikely (status)) return status;
 	status = _cairo_path_fixed_line_to (path, trap.right.p1.x, trap.top);
-	if (status) return status;
+	if (unlikely (status)) return status;
 	status = _cairo_path_fixed_line_to (path, trap.right.p2.x, trap.bottom);
-	if (status) return status;
+	if (unlikely (status)) return status;
 	status = _cairo_path_fixed_line_to (path, trap.left.p2.x, trap.bottom);
-	if (status) return status;
+	if (unlikely (status)) return status;
 	status = _cairo_path_fixed_close_path (path);
-	if (status) return status;
+	if (unlikely (status)) return status;
     }
 
     return CAIRO_STATUS_SUCCESS;
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index e8be4b4..b3a4815 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -146,7 +146,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
                                           TT_TAG_head, 0,
 					  (unsigned char *) &head,
                                           &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     size = sizeof (tt_maxp_t);
@@ -154,7 +154,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
                                            TT_TAG_maxp, 0,
 					   (unsigned char *) &maxp,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     size = sizeof (tt_hhea_t);
@@ -162,7 +162,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
                                            TT_TAG_hhea, 0,
 					   (unsigned char *) &hhea,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     size = 0;
@@ -170,7 +170,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 	                                   TT_TAG_name, 0,
 					   NULL,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     name = malloc(size);
@@ -181,7 +181,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 					   TT_TAG_name, 0,
 					   (unsigned char *) name,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	goto fail0;
 
     font = malloc (sizeof (cairo_truetype_font_t));
@@ -198,7 +198,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->last_boundary = 0;
     _cairo_array_init (&font->output, sizeof (char));
     status = _cairo_array_grow_by (&font->output, 4096);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     font->glyphs = calloc (font->num_glyphs_in_face + 1, sizeof (subset_glyph_t));
@@ -277,7 +277,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 
     _cairo_array_init (&font->string_offsets, sizeof (unsigned long));
     status = _cairo_array_grow_by (&font->string_offsets, 10);
-    if (status)
+    if (unlikely (status))
 	goto fail5;
 
     font->status = CAIRO_STATUS_SUCCESS;
@@ -328,7 +328,7 @@ cairo_truetype_font_allocate_write_buffer (cairo_truetype_font_t  *font,
 	return font->status;
 
     status = _cairo_array_allocate (&font->output, length, (void **) buffer);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -345,7 +345,7 @@ cairo_truetype_font_write (cairo_truetype_font_t *font,
 	return;
 
     status = _cairo_array_append_multiple (&font->output, data, length);
-    if (status)
+    if (unlikely (status))
 	status = _cairo_truetype_font_set_error (font, status);
 }
 
@@ -391,7 +391,7 @@ cairo_truetype_font_align_output (cairo_truetype_font_t	    *font,
 
 	status = cairo_truetype_font_allocate_write_buffer (font, pad,
 		                                            &padding);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	memset (padding, 0, pad);
@@ -413,7 +413,7 @@ cairo_truetype_font_check_boundary (cairo_truetype_font_t *font,
     {
         status = _cairo_array_append (&font->string_offsets,
 				      &font->last_boundary);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_truetype_font_set_error (font, status);
 
         font->last_offset = font->last_boundary;
@@ -486,16 +486,16 @@ cairo_truetype_font_write_generic_table (cairo_truetype_font_t *font,
     size = 0;
     status = font->backend->load_truetype_table(font->scaled_font_subset->scaled_font,
 					        tag, 0, NULL, &size);
-    if (status)
+    if (unlikely (status))
         return _cairo_truetype_font_set_error (font, status);
 
     status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 tag, 0, buffer, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -533,7 +533,7 @@ cairo_truetype_font_remap_composite_glyph (cairo_truetype_font_t	*font,
 	flags = be16_to_cpu (composite_glyph->flags);
         has_more_components = flags & TT_MORE_COMPONENTS;
         status = cairo_truetype_font_use_glyph (font, be16_to_cpu (composite_glyph->index), &index);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
         composite_glyph->index = cpu_to_be16 (index);
@@ -575,7 +575,7 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 TT_TAG_head, 0,
 						 (unsigned char*) &header, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
     
     if (be16_to_cpu (header.index_to_loc_format) == 0)
@@ -589,7 +589,7 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
                                                  TT_TAG_loca, 0, u.bytes, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     start_offset = _cairo_array_num_elements (&font->output);
@@ -612,33 +612,33 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
 
 	size = end - begin;
         status = cairo_truetype_font_align_output (font, &next);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
         status = cairo_truetype_font_check_boundary (font, next);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
         font->glyphs[i].location = next - start_offset;
 
 	status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
         if (size != 0) {
             status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 							 TT_TAG_glyf, begin, buffer, &size);
-	    if (status)
+	    if (unlikely (status))
 		goto FAIL;
 
             status = cairo_truetype_font_remap_composite_glyph (font, buffer, size);
-	    if (status)
+	    if (unlikely (status))
 		goto FAIL;
         }
     }
 
     status = cairo_truetype_font_align_output (font, &next);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     font->glyphs[i].location = next - start_offset;
@@ -664,17 +664,17 @@ cairo_truetype_font_write_head_table (cairo_truetype_font_t *font,
     size = 0;
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 tag, 0, NULL, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     font->checksum_index = _cairo_array_num_elements (&font->output) + 8;
     status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 tag, 0, buffer, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     /* set checkSumAdjustment to 0 for table checksum calcualtion */
@@ -695,12 +695,12 @@ cairo_truetype_font_write_hhea_table (cairo_truetype_font_t *font, unsigned long
 
     size = sizeof (tt_hhea_t);
     status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &hhea);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 tag, 0, (unsigned char *) hhea, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     hhea->num_hmetrics = cpu_to_be16 ((uint16_t)(font->base.num_glyphs));
@@ -728,7 +728,7 @@ cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font,
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 TT_TAG_hhea, 0,
 						 (unsigned char*) &hhea, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     num_hmetrics = be16_to_cpu(hhea.num_hmetrics);
@@ -739,7 +739,7 @@ cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font,
         status = cairo_truetype_font_allocate_write_buffer (font,
 		                                            long_entry_size,
 							    (unsigned char **) &p);
-	if (status)
+	if (unlikely (status))
 	    return _cairo_truetype_font_set_error (font, status);
 
         if (font->glyphs[i].parent_index < num_hmetrics) {
@@ -747,7 +747,7 @@ cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font,
                                                          TT_TAG_hmtx,
                                                          font->glyphs[i].parent_index * long_entry_size,
                                                          (unsigned char *) p, &long_entry_size);
-	    if (status)
+	    if (unlikely (status))
 		return _cairo_truetype_font_set_error (font, status);
         }
         else
@@ -756,7 +756,7 @@ cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font,
                                                          TT_TAG_hmtx,
 							 (num_hmetrics - 1) * long_entry_size,
 							 (unsigned char *) p, &short_entry_size);
-	    if (status)
+	    if (unlikely (status))
 		return _cairo_truetype_font_set_error (font, status);
 
             status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
@@ -764,7 +764,7 @@ cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font,
 							 num_hmetrics * long_entry_size +
 							 (font->glyphs[i].parent_index - num_hmetrics) * short_entry_size,
 							 (unsigned char *) (p + 1), &short_entry_size);
-	    if (status)
+	    if (unlikely (status))
 		return _cairo_truetype_font_set_error (font, status);
         }
         font->base.widths[i] = be16_to_cpu (p[0]);
@@ -789,7 +789,7 @@ cairo_truetype_font_write_loca_table (cairo_truetype_font_t *font,
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 TT_TAG_head, 0,
 						 (unsigned char*) &header, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     if (be16_to_cpu (header.index_to_loc_format) == 0)
@@ -817,12 +817,12 @@ cairo_truetype_font_write_maxp_table (cairo_truetype_font_t *font,
 
     size = sizeof (tt_maxp_t);
     status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &maxp);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
 						 tag, 0, (unsigned char *) maxp, &size);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     maxp->num_glyphs = cpu_to_be16 (font->base.num_glyphs);
@@ -862,7 +862,7 @@ cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font)
     table_buffer_length = font->num_tables * 16;
     status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length,
 						      &table_buffer);
-    if (status)
+    if (unlikely (status))
 	return _cairo_truetype_font_set_error (font, status);
 
     return CAIRO_STATUS_SUCCESS;
@@ -920,28 +920,28 @@ cairo_truetype_font_generate (cairo_truetype_font_t  *font,
 	return font->status;
 
     status = cairo_truetype_font_write_offset_table (font);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     status = cairo_truetype_font_align_output (font, &start);
-    if (status)
+    if (unlikely (status))
 	goto FAIL;
 
     end = 0;
     for (i = 0; i < font->num_tables; i++) {
 	status = font->truetype_tables[i].write (font, font->truetype_tables[i].tag);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	end = _cairo_array_num_elements (&font->output);
 	status = cairo_truetype_font_align_output (font, &next);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	cairo_truetype_font_update_entry (font, font->truetype_tables[i].pos,
                                           font->truetype_tables[i].tag, start, end);
         status = cairo_truetype_font_check_boundary (font, next);
-	if (status)
+	if (unlikely (status))
 	    goto FAIL;
 
 	start = next;
@@ -1081,20 +1081,20 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
     unsigned long num_strings = 0;
 
     status = _cairo_truetype_font_create (font_subset, &font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
 	unsigned short parent_glyph = font->scaled_font_subset->glyphs[i];
 	status = cairo_truetype_font_use_glyph (font, parent_glyph, &parent_glyph);
-	if (status)
+	if (unlikely (status))
 	    goto fail1;
     }
 
     cairo_truetype_font_create_truetype_table_list (font);
     status = cairo_truetype_font_generate (font, &data, &length,
                                            &string_offsets, &num_strings);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     truetype_subset->base_font = strdup (font->base.base_font);
@@ -1199,7 +1199,7 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
                                            TT_TAG_cmap, table_offset,
 					   (unsigned char *) &buf,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* All table formats have the same first two words */
@@ -1216,7 +1216,7 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
                                            TT_TAG_cmap, table_offset,
                                            (unsigned char *) map,
                                            &size);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     num_segments = be16_to_cpu (map->segCountX2)/2;
@@ -1299,7 +1299,7 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
                                            TT_TAG_cmap, 0,
 					   (unsigned char *) &buf,
 					   &size);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     cmap = (tt_cmap_t *) buf;
@@ -1313,7 +1313,7 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
 	                                   TT_TAG_cmap, 0,
 					   (unsigned char *) cmap,
 					   &size);
-    if (status)
+    if (unlikely (status))
         goto cleanup;
 
     /* Find a table with Unicode mapping */
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 1f39a3f..d54215d 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -112,7 +112,7 @@ cairo_type1_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
 							&ctm,
 							&font_options);
     status = font->type1_scaled_font->status;
-    if (status)
+    if (unlikely (status))
         goto fail;
 
     _cairo_array_init (&font->contents, sizeof (unsigned char));
@@ -227,7 +227,7 @@ _charstring_move_to (void          *closure,
     cairo_status_t status;
 
     status = _cairo_array_grow_by (path_info->data, 12);
-    if (status)
+    if (unlikely (status))
         return status;
 
     dx = _cairo_fixed_integer_part (point->x) - path_info->current_x;
@@ -251,7 +251,7 @@ _charstring_line_to (void          *closure,
     cairo_status_t status;
 
     status = _cairo_array_grow_by (path_info->data, 12);
-    if (status)
+    if (unlikely (status))
         return status;
 
     dx = _cairo_fixed_integer_part (point->x) - path_info->current_x;
@@ -277,7 +277,7 @@ _charstring_curve_to (void	    *closure,
     cairo_status_t status;
 
     status = _cairo_array_grow_by (path_info->data, 32);
-    if (status)
+    if (unlikely (status))
         return status;
 
     dx1 = _cairo_fixed_integer_part (point1->x) - path_info->current_x;
@@ -309,7 +309,7 @@ _charstring_close_path (void *closure)
         return CAIRO_STATUS_SUCCESS;
 
     status = _cairo_array_grow_by (path_info->data, 2);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     charstring_encode_command (path_info->data, CHARSTRING_closepath);
@@ -363,7 +363,7 @@ cairo_type1_font_create_charstring (cairo_type1_font_t      *font,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS,
 					     &scaled_glyph);
     }
-    if (status)
+    if (unlikely (status))
         return status;
 
     metrics = &scaled_glyph->metrics;
@@ -385,7 +385,7 @@ cairo_type1_font_create_charstring (cairo_type1_font_t      *font,
     font->widths[subset_index] = metrics->x_advance;
 
     status = _cairo_array_grow_by (data, 30);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (type == CAIRO_CHARSTRING_TYPE1) {
@@ -413,12 +413,12 @@ cairo_type1_font_create_charstring (cairo_type1_font_t      *font,
 					      _charstring_curve_to,
 					      _charstring_close_path,
 					      &path_info);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
     status = _cairo_array_grow_by (data, 1);
-    if (status)
+    if (unlikely (status))
         return status;
     charstring_encode_command (path_info.data, CHARSTRING_endchar);
 
@@ -437,7 +437,7 @@ cairo_type1_font_write_charstrings (cairo_type1_font_t    *font,
 
     _cairo_array_init (&data, sizeof (unsigned char));
     status = _cairo_array_grow_by (&data, 1024);
-    if (status)
+    if (unlikely (status))
         goto fail;
 
     _cairo_output_stream_printf (encrypted_output,
@@ -449,14 +449,14 @@ cairo_type1_font_write_charstrings (cairo_type1_font_t    *font,
         _cairo_array_truncate (&data, 0);
         /* four "random" bytes required by encryption algorithm */
         status = _cairo_array_append_multiple (&data, zeros, 4);
-        if (status)
+        if (unlikely (status))
             goto fail;
 
         status = cairo_type1_font_create_charstring (font, i,
 						     font->scaled_font_subset->glyphs[i],
                                                      CAIRO_CHARSTRING_TYPE1,
 						     &data);
-        if (status)
+        if (unlikely (status))
             goto fail;
 
         charstring_encrypt (&data);
@@ -599,7 +599,7 @@ cairo_type1_font_write_private_dict (cairo_type1_font_t *font,
                                  "/password 5839 def\n");
 
     status = cairo_type1_font_write_charstrings (font, encrypted_output);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     _cairo_output_stream_printf (encrypted_output,
@@ -651,7 +651,7 @@ cairo_type1_font_write (cairo_type1_font_t *font,
     font->header_size = _cairo_output_stream_get_position (font->output);
 
     status = cairo_type1_font_write_private_dict (font, name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->data_size = _cairo_output_stream_get_position (font->output) -
@@ -671,7 +671,7 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
     cairo_int_status_t status;
 
     status = _cairo_array_grow_by (&font->contents, 4096);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font);
@@ -679,7 +679,7 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
 	return _cairo_output_stream_destroy (font->output);
 
     status = cairo_type1_font_write (font, name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->data = _cairo_array_index (&font->contents, 0);
@@ -714,11 +714,11 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t	*type1_subset,
     unsigned int i, len;
 
     status = cairo_type1_font_create (scaled_font_subset, &font, hex_encode);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_type1_font_generate (font, name);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     type1_subset->base_font = strdup (name);
@@ -816,7 +816,7 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
     cairo_array_t charstring;
 
     status = cairo_type1_font_create (scaled_font_subset, &font, FALSE);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_array_init (&type2_subset->charstrings, sizeof (cairo_array_t));
@@ -831,18 +831,18 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
         _cairo_array_init (&charstring, sizeof (unsigned char));
         status = _cairo_array_grow_by (&charstring, 32);
-        if (status)
+        if (unlikely (status))
             goto fail2;
 
 	status = cairo_type1_font_create_charstring (font, i,
 						     font->scaled_font_subset->glyphs[i],
 						     CAIRO_CHARSTRING_TYPE2,
 						     &charstring);
-        if (status)
+        if (unlikely (status))
             goto fail2;
 
         status = _cairo_array_append (&type2_subset->charstrings, &charstring);
-        if (status)
+        if (unlikely (status))
             goto fail2;
     }
     _cairo_scaled_font_thaw_cache (font->type1_scaled_font);
diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index e555758..a62a261 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -866,11 +866,11 @@ cairo_type1_font_subset_look_for_seac(cairo_type1_font_subset_t *font,
 		 * make sure those glyphs are present in the subset
 		 * under their standard names. */
 		status = use_standard_encoding_glyph (font, stack[3]);
-		if (status)
+		if (unlikely (status))
 		    return status;
 
 		status = use_standard_encoding_glyph (font, stack[4]);
-		if (status)
+		if (unlikely (status))
 		    return status;
 
 		sp = 0;
@@ -906,18 +906,18 @@ write_used_glyphs (cairo_type1_font_subset_t *font,
 		       "/%.*s %d %s ",
 		       name_length, name, charstring_length, font->rd);
     status = cairo_type1_font_subset_write_encrypted (font, buffer, length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_type1_font_subset_write_encrypted (font,
 					              charstring,
 						      charstring_length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     length = snprintf (buffer, sizeof buffer, "%s\n", font->nd);
     status = cairo_type1_font_subset_write_encrypted (font, buffer, length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -983,7 +983,7 @@ cairo_type1_font_subset_for_each_glyph (cairo_type1_font_subset_t *font,
 	    cairo_status_t status = func (font,
 		                          name, name_length,
 					  charstring, charstring_length);
-	    if (status)
+	    if (unlikely (status))
 		return status;
 	}
     }
@@ -1040,7 +1040,7 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
     dict_start = p;
 
     status = cairo_type1_font_subset_get_glyph_names_and_widths (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Now that we have the private dictionary broken down in
@@ -1052,7 +1052,7 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
 						     font->cleartext_end,
 						     cairo_type1_font_subset_look_for_seac,
 						     &p);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     closefile_token = find_token (p, font->cleartext_end, "closefile");
@@ -1060,13 +1060,13 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     status = cairo_type1_font_subset_get_glyph_names_and_widths (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* We're ready to start outputting. First write the header,
      * i.e. the public part of the font dict.*/
     status = cairo_type1_font_subset_write_header (font, name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->base.header_size = _cairo_output_stream_get_position (font->output);
@@ -1076,21 +1076,21 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
      * to the /CharStrings token. */
     status = cairo_type1_font_subset_write_encrypted (font, font->cleartext,
 					         charstrings - font->cleartext);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Write out new charstring count */
     length = snprintf (buffer, sizeof buffer,
 		       "/CharStrings %d", font->num_glyphs);
     status = cairo_type1_font_subset_write_encrypted (font, buffer, length);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Write out text between the charstring count and the first
      * charstring definition */
     status = cairo_type1_font_subset_write_encrypted (font, glyph_count_end,
 	                                          dict_start - glyph_count_end);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Write out the charstring definitions for each of the glyphs in
@@ -1100,14 +1100,14 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
 						     font->cleartext_end,
 						     write_used_glyphs,
 						     &p);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Output what's left between the end of the glyph definitions and
      * the end of the private dict to the output. */
     status = cairo_type1_font_subset_write_encrypted (font, p,
 	                        closefile_token - p + strlen ("closefile") + 1);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     _cairo_output_stream_write (font->output, "\n", 1);
@@ -1158,11 +1158,11 @@ cairo_type1_font_subset_write (cairo_type1_font_subset_t *font,
     cairo_status_t status;
 
     status = cairo_type1_font_subset_find_segments (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = cairo_type1_font_subset_decrypt_eexec_segment (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* Determine which glyph definition delimiters to use. */
@@ -1181,14 +1181,14 @@ cairo_type1_font_subset_write (cairo_type1_font_subset_t *font,
     font->hex_column = 0;
 
     status = cairo_type1_font_subset_write_private_dict (font, name);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->base.data_size = _cairo_output_stream_get_position (font->output) -
 	font->base.header_size;
 
     status = cairo_type1_font_subset_write_trailer (font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     font->base.trailer_size =
@@ -1239,7 +1239,7 @@ cairo_type1_font_subset_generate (void       *abstract_font,
     }
 
     status = _cairo_array_grow_by (&font->contents, 4096);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     font->output = _cairo_output_stream_create (type1_font_write, NULL, font);
@@ -1249,7 +1249,7 @@ cairo_type1_font_subset_generate (void       *abstract_font,
     }
 
     status = cairo_type1_font_subset_write (font, name);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     font->base.data = _cairo_array_index (&font->contents, 0);
@@ -1306,7 +1306,7 @@ _cairo_type1_subset_init (cairo_type1_subset_t		*type1_subset,
     unscaled_font = _cairo_ft_scaled_font_get_unscaled_font (scaled_font_subset->scaled_font);
 
     status = _cairo_type1_font_subset_init (&font, unscaled_font, hex_encode);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     for (i = 0; i < scaled_font_subset->num_glyphs; i++) {
@@ -1315,7 +1315,7 @@ _cairo_type1_subset_init (cairo_type1_subset_t		*type1_subset,
     }
 
     status = cairo_type1_font_subset_generate (&font, name);
-    if (status)
+    if (unlikely (status))
 	goto fail1;
 
     if (font.base.base_font) {
diff --git a/src/cairo-type3-glyph-surface.c b/src/cairo-type3-glyph-surface.c
index 6f9eb43..7106040 100644
--- a/src/cairo-type3-glyph-surface.c
+++ b/src/cairo-type3-glyph-surface.c
@@ -96,7 +96,7 @@ _cairo_type3_glyph_surface_emit_image (cairo_type3_glyph_surface_t *surface,
     } else {
 	image_mask = _cairo_image_surface_clone (image, CAIRO_FORMAT_A1);
 	status = cairo_surface_status (&image->base);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -196,7 +196,7 @@ _cairo_type3_glyph_surface_paint (void			*abstract_surface,
 
     pattern = (const cairo_surface_pattern_t *) source;
     status = _cairo_surface_acquire_source_image (pattern->surface, &image, &image_extra);
-    if (status)
+    if (unlikely (status))
 	goto fail;
 
     status = _cairo_type3_glyph_surface_emit_image_pattern (surface,
@@ -282,7 +282,7 @@ _cairo_type3_glyph_surface_show_glyphs (void		     *abstract_surface,
     /* We require the matrix to be invertable. */
     ctm_inverse = scaled_font->ctm;
     status = cairo_matrix_invert (&ctm_inverse);
-    if (status)
+    if (unlikely (status))
 	return CAIRO_INT_STATUS_IMAGE_FALLBACK;
 
     cairo_matrix_multiply (&new_ctm, &scaled_font->ctm, &ctm_inverse);
@@ -357,7 +357,7 @@ _cairo_type3_glyph_surface_emit_fallback_image (cairo_type3_glyph_surface_t *sur
 					 CAIRO_SCALED_GLYPH_INFO_METRICS |
 					 CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					 &scaled_glyph);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     image = scaled_glyph->surface;
@@ -419,7 +419,7 @@ _cairo_type3_glyph_surface_analyze_glyph (void		     *abstract_surface,
 
     status = _cairo_meta_surface_replay (scaled_glyph->meta_surface,
 					 &surface->base);
-    if (status)
+    if (unlikely (status))
 	goto cleanup;
 
     status2 = _cairo_pdf_operators_flush (&surface->pdf_operators);
diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index c272966..5e2077f 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -127,7 +127,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 
 	cairo_destroy (cr);
 
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_surface_destroy (meta_surface);
 	    return status;
 	}
@@ -152,7 +152,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	    analysis_surface = _cairo_analysis_surface_create (null_surface, -1, -1);
 	    cairo_surface_destroy (null_surface);
 	    status = analysis_surface->status;
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_analysis_surface_set_ctm (analysis_surface,
@@ -162,7 +162,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	    _cairo_analysis_surface_get_bounding_box (analysis_surface, &bbox);
 	    cairo_surface_destroy (analysis_surface);
 
-	    if (status)
+	    if (unlikely (status))
 		return status;
 
 	    _cairo_box_to_doubles (&bbox, &x1, &y1, &x2, &y2);
@@ -215,7 +215,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	                                 - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y));
 	status = _cairo_meta_surface_replay (meta_surface, surface);
 
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_surface_destroy(surface);
 	    return status;
 	}
@@ -232,7 +232,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 
 	status = _cairo_meta_surface_get_path (meta_surface, path);
 
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_path_fixed_destroy (path);
 	    return status;
 	}
@@ -355,7 +355,7 @@ _cairo_user_scaled_font_get_implementation (cairo_toy_font_face_t *toy_face,
 						face,
 						(cairo_destroy_func_t) cairo_font_face_destroy);
 
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_font_face_destroy (face);
 	    return status;
 	}
@@ -376,7 +376,7 @@ _cairo_user_scaled_font_create_toy (cairo_toy_font_face_t     *toy_face,
     cairo_status_t status;
 
     status = _cairo_user_scaled_font_get_implementation (toy_face, &face);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     status = _cairo_user_font_face_scaled_font_create (face,
@@ -384,7 +384,7 @@ _cairo_user_scaled_font_create_toy (cairo_toy_font_face_t     *toy_face,
 						       ctm,
 						       font_options,
 						       font);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -428,7 +428,7 @@ _cairo_user_font_face_scaled_font_create (void                        *abstract_
 				      font_matrix, ctm, options,
 				      &_cairo_user_scaled_font_backend);
 
-    if (status) {
+    if (unlikely (status)) {
 	free (user_scaled_font);
 	return status;
     }
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 9dd411e..1878f8e 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -485,7 +485,7 @@ _cairo_xlib_screen_get_visual_info (cairo_xlib_screen_info_t *info,
 					     XScreenNumberOfScreen (info->screen),
 					     visual->visualid,
 					     &ret);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     CAIRO_MUTEX_LOCK (info->mutex);
@@ -506,7 +506,7 @@ _cairo_xlib_screen_get_visual_info (cairo_xlib_screen_info_t *info,
 	status = _cairo_array_append (&info->visuals, &ret);
     CAIRO_MUTEX_UNLOCK (info->mutex);
 
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_xlib_visual_info_destroy (dpy, ret);
 	return status;
     }
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 136e554..75d4de3 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -672,7 +672,7 @@ _get_image_surface (cairo_xlib_surface_t    *surface,
 	Pixmap pixmap;
 
 	status = _cairo_xlib_surface_ensure_gc (surface);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	pixmap = XCreatePixmap (surface->dpy,
@@ -717,7 +717,7 @@ _get_image_surface (cairo_xlib_surface_t    *surface,
 							    ximage->height,
 							    ximage->bytes_per_line);
 	status = image->base.status;
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	/* Let the surface take ownership of the data */
@@ -778,14 +778,14 @@ _get_image_surface (cairo_xlib_surface_t    *surface,
 	    status = _cairo_xlib_screen_get_visual_info (surface->screen_info,
 							 surface->visual,
 							 &visual_info);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 	}
 
 	image = (cairo_image_surface_t *) cairo_image_surface_create
 	    (format, ximage->width, ximage->height);
 	status = image->base.status;
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	data = cairo_image_surface_get_data (&image->base);
@@ -822,7 +822,7 @@ _get_image_surface (cairo_xlib_surface_t    *surface,
  BAIL:
     XDestroyImage (ximage);
 
-    if (status) {
+    if (unlikely (status)) {
 	if (image) {
 	    cairo_surface_destroy (&image->base);
 	    image = NULL;
@@ -1014,7 +1014,7 @@ _draw_image_surface (cairo_xlib_surface_t   *surface,
 	    status = _cairo_xlib_screen_get_visual_info (surface->screen_info,
 							 surface->visual,
 							 &visual_info);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 	}
 
@@ -1071,7 +1071,7 @@ _draw_image_surface (cairo_xlib_surface_t   *surface,
     }
 
     status = _cairo_xlib_surface_ensure_gc (surface);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     XPutImage(surface->dpy, surface->drawable, surface->gc,
@@ -1097,7 +1097,7 @@ _cairo_xlib_surface_acquire_source_image (void                    *abstract_surf
     _cairo_xlib_display_notify (surface->display);
 
     status = _get_image_surface (surface, NULL, &image, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *image_out = image;
@@ -1128,7 +1128,7 @@ _cairo_xlib_surface_acquire_dest_image (void                    *abstract_surfac
     _cairo_xlib_display_notify (surface->display);
 
     status = _get_image_surface (surface, interest_rect, &image, image_rect_out);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     *image_out = image;
@@ -1217,7 +1217,7 @@ _cairo_xlib_surface_clone_similar (void			*abstract_surface,
 				      src_x, src_y,
 			              width, height,
 				      0, 0);
-	if (status) {
+	if (unlikely (status)) {
 	    cairo_surface_destroy (&clone->base);
 	    return status;
 	}
@@ -1264,7 +1264,7 @@ _cairo_xlib_surface_create_solid_pattern_surface (void                  *abstrac
 	    _cairo_image_surface_create_with_content (solid_pattern->content,
 						      width, height);
     status = image->base.status;
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     pixmap = XCreatePixmap (other->dpy,
@@ -1280,26 +1280,26 @@ _cairo_xlib_surface_create_solid_pattern_surface (void                  *abstrac
 						   width, height,
 						   other->depth);
     status = surface->base.status;
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _cairo_surface_paint (&image->base,
 				   CAIRO_OPERATOR_SOURCE,
 				   &solid_pattern->base, NULL);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     status = _draw_image_surface (surface, image,
 				  0, 0,
 				  width, height,
 				  0, 0);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
   BAIL:
     cairo_surface_destroy (&image->base);
 
-    if (status) {
+    if (unlikely (status)) {
 	if (pixmap != None)
 	    XFreePixmap (other->dpy, pixmap);
 	cairo_surface_destroy (&surface->base);
@@ -1426,7 +1426,7 @@ _cairo_xlib_surface_set_attributes (cairo_xlib_surface_t	    *surface,
 
     status = _cairo_xlib_surface_set_matrix (surface, &attributes->matrix,
 					     xc, yc);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     switch (attributes->extend) {
@@ -1443,7 +1443,7 @@ _cairo_xlib_surface_set_attributes (cairo_xlib_surface_t	    *surface,
     }
 
     status = _cairo_xlib_surface_set_filter (surface, attributes->filter);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1728,7 +1728,7 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 					      (cairo_surface_t **) &src,
 					      (cairo_surface_t **) &mask,
 					      &src_attr, &mask_attr);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     /* check for fallback surfaces that we cannot handle ... */
@@ -1757,7 +1757,7 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 	status = _cairo_xlib_surface_set_attributes (src, &src_attr,
 						     dst_x + width / 2.,
 						     dst_y + height / 2.);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	_cairo_xlib_surface_ensure_dst_picture (dst);
@@ -1765,7 +1765,7 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 	    status = _cairo_xlib_surface_set_attributes (mask, &mask_attr,
 							 dst_x + width / 2.,
 							 dst_y + height/ 2.);
-	    if (status)
+	    if (unlikely (status))
 		goto BAIL;
 
 	    XRenderComposite (dst->dpy,
@@ -1796,7 +1796,7 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 
     case DO_XCOPYAREA:
 	status = _cairo_xlib_surface_ensure_gc (dst);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	is_integer_translation = _cairo_matrix_is_integer_translation (&src_attr.matrix,
@@ -1824,7 +1824,7 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 	 */
 
 	status = _cairo_xlib_surface_ensure_gc (dst);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 	is_integer_translation = _cairo_matrix_is_integer_translation (&src_attr.matrix,
 								       &itx, &ity);
@@ -1879,7 +1879,7 @@ _cairo_xlib_surface_solid_fill_rectangles (cairo_xlib_surface_t    *surface,
     _cairo_pattern_init_solid (&solid, color, CAIRO_CONTENT_COLOR);
 
     status = _cairo_xlib_surface_ensure_gc (surface);
-    if (status)
+    if (unlikely (status))
         return status;
 
     status = _cairo_pattern_acquire_surface (&solid.base, &surface->base,
@@ -1888,7 +1888,7 @@ _cairo_xlib_surface_solid_fill_rectangles (cairo_xlib_surface_t    *surface,
 					     ARRAY_LENGTH (dither_pattern),
 					     &solid_surface,
 					     &attrs);
-    if (status)
+    if (unlikely (status))
         return status;
 
     if (! _cairo_surface_is_xlib (solid_surface)) {
@@ -2136,7 +2136,7 @@ _cairo_xlib_surface_composite_trapezoids (cairo_operator_t	op,
 					     src_x, src_y, width, height,
 					     (cairo_surface_t **) &src,
 					     &attributes);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     operation = _recategorize_composite_operation (dst, op, src,
@@ -2177,7 +2177,7 @@ _cairo_xlib_surface_composite_trapezoids (cairo_operator_t	op,
     status = _cairo_xlib_surface_set_attributes (src, &attributes,
 						 dst_x + width / 2.,
 						 dst_y + height / 2.);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     if (!_cairo_operator_bounded_by_mask (op)) {
@@ -2300,7 +2300,7 @@ _cairo_xlib_surface_set_clip_region (void           *abstract_surface,
 	_cairo_region_init_rect (&bound, &rect);
 	_cairo_region_init (&bounded);
 	status = _cairo_region_intersect (&bounded, &bound, region);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_region_fini (&bound);
 	    _cairo_region_fini (&bounded);
 	    return status;
@@ -2309,7 +2309,7 @@ _cairo_xlib_surface_set_clip_region (void           *abstract_surface,
 	n_boxes = sizeof (surface->embedded_clip_rects) / sizeof (cairo_box_int_t);
 	boxes = (cairo_box_int_t *) surface->embedded_clip_rects;
 	status = _cairo_region_get_boxes (&bounded, &n_boxes, &boxes);
-	if (status) {
+	if (unlikely (status)) {
 	    _cairo_region_fini (&bound);
 	    _cairo_region_fini (&bounded);
 	    return status;
@@ -2429,7 +2429,7 @@ _cairo_xlib_surface_reset (void *abstract_surface)
     cairo_status_t status;
 
     status = _cairo_xlib_surface_set_clip_region (surface, NULL);
-    if (status)
+    if (unlikely (status))
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
@@ -2564,11 +2564,11 @@ _cairo_xlib_surface_create_internal (Display		       *dpy,
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL));
 
     status = _cairo_xlib_display_get (dpy, &display);
-    if (status)
+    if (unlikely (status))
 	return _cairo_surface_create_in_error (status);
 
     status = _cairo_xlib_screen_info_get (display, screen, &screen_info);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_xlib_display_destroy (display);
 	return _cairo_surface_create_in_error (status);
     }
@@ -2903,7 +2903,7 @@ cairo_xlib_surface_set_drawable (cairo_surface_t   *abstract_surface,
 		                                  surface->display,
 						  XRenderFreePicture,
 						  surface->dst_picture);
-	    if (status) {
+	    if (unlikely (status)) {
 		status = _cairo_surface_set_error (&surface->base, status);
 		return;
 	    }
@@ -2916,7 +2916,7 @@ cairo_xlib_surface_set_drawable (cairo_surface_t   *abstract_surface,
 		                                  surface->display,
 						  XRenderFreePicture,
 						  surface->src_picture);
-	    if (status) {
+	    if (unlikely (status)) {
 		status = _cairo_surface_set_error (&surface->base, status);
 		return;
 	    }
@@ -3173,7 +3173,7 @@ _cairo_xlib_surface_font_init (Display		    *dpy,
 
     font_private->scaled_font = scaled_font;
     status = _cairo_xlib_display_get (dpy, &font_private->display);
-    if (status) {
+    if (unlikely (status)) {
 	free (font_private);
 	return status;
     }
@@ -3289,7 +3289,7 @@ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
 		    to_free,
 		    free);
 	    /* XXX cannot propagate failure */
-	    if (status)
+	    if (unlikely (status))
 		free (to_free);
 
 	    to_free = glyphset_info->pending_free_glyphs = NULL;
@@ -3445,7 +3445,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 					     CAIRO_SCALED_GLYPH_INFO_METRICS |
 					     CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					     pscaled_glyph);
-	if (status)
+	if (unlikely (status))
 	    return status;
 
 	scaled_glyph = *pscaled_glyph;
@@ -3457,7 +3457,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 
     if (scaled_font->surface_private == NULL) {
 	status = _cairo_xlib_surface_font_init (dpy, scaled_font);
-	if (status)
+	if (unlikely (status))
 	    return status;
     }
 
@@ -3484,7 +3484,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 
 	tmp_surface = cairo_image_surface_create (glyphset_info->format, 1, 1);
 	status = tmp_surface->status;
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	cr = cairo_create (tmp_surface);
@@ -3498,7 +3498,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 
 	glyph_surface = (cairo_image_surface_t *) tmp_surface;
 
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
     }
 
@@ -3514,7 +3514,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 						  glyph_surface->width,
 						  glyph_surface->height);
 	status = tmp_surface->status;
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
 
 	tmp_surface->device_transform = glyph_surface->base.device_transform;
@@ -3529,7 +3529,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 
 	glyph_surface = (cairo_image_surface_t *) tmp_surface;
 
-	if (status)
+	if (unlikely (status))
 	    goto BAIL;
     }
 
@@ -3864,7 +3864,7 @@ _cairo_xlib_surface_emit_glyphs (cairo_xlib_surface_t *dst,
 	    status = _cairo_xlib_surface_add_glyph (dst->dpy,
 		                                    scaled_font,
 						    &scaled_glyph);
-	    if (status) {
+	    if (unlikely (status)) {
 	        if (status == CAIRO_INT_STATUS_UNSUPPORTED)
 		    /* Break so we flush glyphs so far and let fallback code
 		     * handle the rest */
@@ -4055,7 +4055,7 @@ _cairo_xlib_surface_show_glyphs (void                *abstract_dst,
                                                  0, 0, 1, 1,
                                                  (cairo_surface_t **) &src,
                                                  &attributes);
-	if (status)
+	if (unlikely (status))
 	    goto BAIL0;
     } else {
         cairo_rectangle_int_t glyph_extents;
@@ -4064,7 +4064,7 @@ _cairo_xlib_surface_show_glyphs (void                *abstract_dst,
                                                           glyphs,
                                                           num_glyphs,
                                                           &glyph_extents);
-        if (status)
+        if (unlikely (status))
 	    goto BAIL0;
 
         status = _cairo_pattern_acquire_surface (src_pattern, &dst->base,
@@ -4072,7 +4072,7 @@ _cairo_xlib_surface_show_glyphs (void                *abstract_dst,
                                                  glyph_extents.width, glyph_extents.height,
                                                  (cairo_surface_t **) &src,
                                                  &attributes);
-        if (status)
+        if (unlikely (status))
 	    goto BAIL0;
     }
 
@@ -4084,7 +4084,7 @@ _cairo_xlib_surface_show_glyphs (void                *abstract_dst,
     }
 
     status = _cairo_xlib_surface_set_attributes (src, &attributes, 0, 0);
-    if (status)
+    if (unlikely (status))
         goto BAIL1;
 
     _cairo_scaled_font_freeze_cache (scaled_font);
diff --git a/src/cairo.c b/src/cairo.c
index 3dc3001..924f7ca 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -168,7 +168,7 @@ cairo_create (cairo_surface_t *target)
     cr->gstate_freelist = NULL;
 
     status = _cairo_gstate_init (cr->gstate, target);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 
     return cr;
@@ -349,7 +349,7 @@ cairo_save (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_save (&cr->gstate, &cr->gstate_freelist);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_save);
@@ -371,7 +371,7 @@ cairo_restore (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_restore);
@@ -458,10 +458,10 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
     parent_surface = _cairo_gstate_get_target (cr->gstate);
     /* Get the extents that we'll use in creating our new group surface */
     status = _cairo_surface_get_extents (parent_surface, &extents);
-    if (status)
+    if (unlikely (status))
 	goto bail;
     status = _cairo_clip_intersect_to_rectangle (_cairo_gstate_get_clip (cr->gstate), &extents);
-    if (status)
+    if (unlikely (status))
 	goto bail;
 
     group_surface = cairo_surface_create_similar (_cairo_gstate_get_target (cr->gstate),
@@ -469,7 +469,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 						  extents.width,
 						  extents.height);
     status = cairo_surface_status (group_surface);
-    if (status)
+    if (unlikely (status))
 	goto bail;
 
     /* Set device offsets on the new surface so that logically it appears at
@@ -490,7 +490,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 
 bail:
     cairo_surface_destroy (group_surface);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_push_group_with_content);
@@ -628,7 +628,7 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 	return;
 
     status = _cairo_gstate_set_operator (cr->gstate, op);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_operator);
@@ -790,7 +790,7 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
     }
 
     status = _cairo_gstate_set_source (cr->gstate, source);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_source);
@@ -838,7 +838,7 @@ cairo_set_tolerance (cairo_t *cr, double tolerance)
     _cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance);
 
     status = _cairo_gstate_set_tolerance (cr->gstate, tolerance);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_tolerance);
@@ -865,7 +865,7 @@ cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 	return;
 
     status = _cairo_gstate_set_antialias (cr->gstate, antialias);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -891,7 +891,7 @@ cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 	return;
 
     status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -932,7 +932,7 @@ cairo_set_line_width (cairo_t *cr, double width)
     _cairo_restrict_value (&width, 0.0, width);
 
     status = _cairo_gstate_set_line_width (cr->gstate, width);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_line_width);
@@ -962,7 +962,7 @@ cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 	return;
 
     status = _cairo_gstate_set_line_cap (cr->gstate, line_cap);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_line_cap);
@@ -992,7 +992,7 @@ cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
 	return;
 
     status = _cairo_gstate_set_line_join (cr->gstate, line_join);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_line_join);
@@ -1042,7 +1042,7 @@ cairo_set_dash (cairo_t	     *cr,
 
     status = _cairo_gstate_set_dash (cr->gstate,
 				     dashes, num_dashes, offset);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1132,7 +1132,7 @@ cairo_set_miter_limit (cairo_t *cr, double limit)
 	return;
 
     status = _cairo_gstate_set_miter_limit (cr->gstate, limit);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1157,7 +1157,7 @@ cairo_translate (cairo_t *cr, double tx, double ty)
 	return;
 
     status = _cairo_gstate_translate (cr->gstate, tx, ty);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1181,7 +1181,7 @@ cairo_scale (cairo_t *cr, double sx, double sy)
 	return;
 
     status = _cairo_gstate_scale (cr->gstate, sx, sy);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_scale);
@@ -1207,7 +1207,7 @@ cairo_rotate (cairo_t *cr, double angle)
 	return;
 
     status = _cairo_gstate_rotate (cr->gstate, angle);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1230,7 +1230,7 @@ cairo_transform (cairo_t	      *cr,
 	return;
 
     status = _cairo_gstate_transform (cr->gstate, matrix);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1252,7 +1252,7 @@ cairo_set_matrix (cairo_t	       *cr,
 	return;
 
     status = _cairo_gstate_set_matrix (cr->gstate, matrix);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_matrix);
@@ -1393,7 +1393,7 @@ cairo_move_to (cairo_t *cr, double x, double y)
     y_fixed = _cairo_fixed_from_double (y);
 
     status = _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_move_to);
@@ -1452,7 +1452,7 @@ cairo_line_to (cairo_t *cr, double x, double y)
     y_fixed = _cairo_fixed_from_double (y);
 
     status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_line_to);
@@ -1507,7 +1507,7 @@ cairo_curve_to (cairo_t *cr,
 					 x1_fixed, y1_fixed,
 					 x2_fixed, y2_fixed,
 					 x3_fixed, y3_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_curve_to);
@@ -1641,7 +1641,7 @@ cairo_arc_to (cairo_t *cr,
 				   x1, y1,
 				   x2, y2,
 				   radius);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 */
@@ -1677,7 +1677,7 @@ cairo_rel_move_to (cairo_t *cr, double dx, double dy)
     dy_fixed = _cairo_fixed_from_double (dy);
 
     status = _cairo_path_fixed_rel_move_to (cr->path, dx_fixed, dy_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1714,7 +1714,7 @@ cairo_rel_line_to (cairo_t *cr, double dx, double dy)
     dy_fixed = _cairo_fixed_from_double (dy);
 
     status = _cairo_path_fixed_rel_line_to (cr->path, dx_fixed, dy_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_rel_line_to);
@@ -1775,7 +1775,7 @@ cairo_rel_curve_to (cairo_t *cr,
 					     dx1_fixed, dy1_fixed,
 					     dx2_fixed, dy2_fixed,
 					     dx3_fixed, dy3_fixed);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -1827,7 +1827,7 @@ cairo_stroke_to_path (cairo_t *cr)
     /* The code in _cairo_meta_surface_get_path has a poorman's stroke_to_path */
 
     status = _cairo_gstate_stroke_path (cr->gstate);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 #endif
@@ -1867,7 +1867,7 @@ cairo_close_path (cairo_t *cr)
 	return;
 
     status = _cairo_path_fixed_close_path (cr->path);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_close_path);
@@ -1941,7 +1941,7 @@ cairo_paint (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_paint (cr->gstate);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_paint);
@@ -1980,7 +1980,7 @@ cairo_paint_with_alpha (cairo_t *cr,
     _cairo_pattern_init_solid (&pattern, &color, CAIRO_CONTENT_ALPHA);
 
     status = _cairo_gstate_mask (cr->gstate, &pattern.base);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 
     _cairo_pattern_fini (&pattern.base);
@@ -2016,7 +2016,7 @@ cairo_mask (cairo_t         *cr,
     }
 
     status = _cairo_gstate_mask (cr->gstate, pattern);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_mask);
@@ -2118,7 +2118,7 @@ cairo_stroke_preserve (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_stroke (cr->gstate, cr->path);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_stroke_preserve);
@@ -2161,7 +2161,7 @@ cairo_fill_preserve (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_fill (cr->gstate, cr->path);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_fill_preserve);
@@ -2187,7 +2187,7 @@ cairo_copy_page (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_copy_page (cr->gstate);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2210,7 +2210,7 @@ cairo_show_page (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_show_page (cr->gstate);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2244,7 +2244,7 @@ cairo_in_stroke (cairo_t *cr, double x, double y)
     status = _cairo_gstate_in_stroke (cr->gstate,
 				      cr->path,
 				      x, y, &inside);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 
     return inside;
@@ -2332,7 +2332,7 @@ cairo_stroke_extents (cairo_t *cr,
     status = _cairo_gstate_stroke_extents (cr->gstate,
 					   cr->path,
 					   x1, y1, x2, y2);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2383,7 +2383,7 @@ cairo_fill_extents (cairo_t *cr,
     status = _cairo_gstate_fill_extents (cr->gstate,
 					 cr->path,
 					 x1, y1, x2, y2);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2448,7 +2448,7 @@ cairo_clip_preserve (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_clip (cr->gstate, cr->path);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_clip_preserve);
@@ -2478,7 +2478,7 @@ cairo_reset_clip (cairo_t *cr)
 	return;
 
     status = _cairo_gstate_reset_clip (cr->gstate);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2516,7 +2516,7 @@ cairo_clip_extents (cairo_t *cr,
     }
 
     status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2622,7 +2622,7 @@ cairo_select_font_face (cairo_t              *cr,
 	return;
 
     status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2650,7 +2650,7 @@ cairo_font_extents (cairo_t              *cr,
 	return;
 
     status = _cairo_gstate_get_font_extents (cr->gstate, extents);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2673,7 +2673,7 @@ cairo_set_font_face (cairo_t           *cr,
 	return;
 
     status = _cairo_gstate_set_font_face (cr->gstate, font_face);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2705,7 +2705,7 @@ cairo_get_font_face (cairo_t *cr)
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
 
     status = _cairo_gstate_get_font_face (cr->gstate, &font_face);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_set_error (cr, status);
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
     }
@@ -2737,7 +2737,7 @@ cairo_set_font_size (cairo_t *cr, double size)
 	return;
 
     status = _cairo_gstate_set_font_size (cr->gstate, size);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_font_size);
@@ -2765,7 +2765,7 @@ cairo_set_font_matrix (cairo_t		    *cr,
 	return;
 
     status = _cairo_gstate_set_font_matrix (cr->gstate, matrix);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -2809,7 +2809,7 @@ cairo_set_font_options (cairo_t                    *cr,
 	return;
 
     status = cairo_font_options_status ((cairo_font_options_t *) options);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_set_error (cr, status);
 	return;
     }
@@ -2873,15 +2873,15 @@ cairo_set_scaled_font (cairo_t                   *cr,
     }
 
     status = scaled_font->status;
-    if (status)
+    if (unlikely (status))
         goto BAIL;
 
     status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face);
-    if (status)
+    if (unlikely (status))
         goto BAIL;
 
     status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix);
-    if (status)
+    if (unlikely (status))
         goto BAIL;
 
     _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
@@ -2922,7 +2922,7 @@ cairo_get_scaled_font (cairo_t *cr)
 	return _cairo_scaled_font_create_in_error (cr->status);
 
     status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font);
-    if (status) {
+    if (unlikely (status)) {
 	_cairo_set_error (cr, status);
 	return _cairo_scaled_font_create_in_error (status);
     }
@@ -2988,7 +2988,7 @@ cairo_text_extents (cairo_t              *cr,
 					      extents);
     cairo_glyph_free (glyphs);
 
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3043,7 +3043,7 @@ cairo_glyph_extents (cairo_t                *cr,
 
     status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs,
 					  extents);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3113,7 +3113,7 @@ cairo_show_text (cairo_t *cr, const char *utf8)
 					   &glyphs, &num_glyphs,
 					   has_show_text_glyphs ? &clusters : NULL, &num_clusters,
 					   &cluster_flags);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     if (num_glyphs == 0)
@@ -3124,14 +3124,14 @@ cairo_show_text (cairo_t *cr, const char *utf8)
 					     glyphs, num_glyphs,
 					     clusters, num_clusters,
 					     cluster_flags);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     last_glyph = &glyphs[num_glyphs - 1];
     status = _cairo_gstate_glyph_extents (cr->gstate,
 					  last_glyph, 1,
 					  &extents);
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     x = last_glyph->x + extents.x_advance;
@@ -3144,7 +3144,7 @@ cairo_show_text (cairo_t *cr, const char *utf8)
     if (clusters != stack_clusters)
 	cairo_text_cluster_free (clusters);
 
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3184,7 +3184,7 @@ cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 					     glyphs, num_glyphs,
 					     NULL, 0,
 					     FALSE);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3287,7 +3287,7 @@ cairo_show_text_glyphs (cairo_t			   *cr,
 					     utf8, utf8_len,
 					     glyphs, num_glyphs,
 					     clusters, num_clusters, cluster_flags);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3339,7 +3339,7 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
 					   NULL, NULL,
 					   NULL);
 
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     if (num_glyphs == 0)
@@ -3349,7 +3349,7 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
 				       glyphs, num_glyphs,
 				       cr->path);
 
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     last_glyph = &glyphs[num_glyphs - 1];
@@ -3357,7 +3357,7 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
 					  last_glyph, 1,
 					  &extents);
 
-    if (status)
+    if (unlikely (status))
 	goto BAIL;
 
     x = last_glyph->x + extents.x_advance;
@@ -3367,7 +3367,7 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
  BAIL:
     cairo_glyph_free (glyphs);
 
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3405,7 +3405,7 @@ cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
     status = _cairo_gstate_glyph_path (cr->gstate,
 				       glyphs, num_glyphs,
 				       cr->path);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
@@ -3825,7 +3825,7 @@ cairo_append_path (cairo_t		*cr,
     }
 
     status = _cairo_path_append_to_context (path, cr);
-    if (status)
+    if (unlikely (status))
 	_cairo_set_error (cr, status);
 }
 
commit f0804d4856496a46d0b2270d5815856bf63b4cf8
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 28 23:58:55 2008 +0000

    [test] Exercise caps and joins under reflection.
    
    The nature of the joins depends critically upon whether the joint is
    clockwise or counter-clockwise, so extend the basic caps-joins test to
    exercise both conditions i.e. repeat the test under a reflection.

diff --git a/test/Makefile.am b/test/Makefile.am
index 7ab086d..de9f9c4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,6 +16,7 @@ test_sources = \
 	caps.c						\
 	caps-joins.c					\
 	caps-joins-alpha.c				\
+	caps-joins-curve.c				\
 	caps-sub-paths.c				\
 	clip-all.c					\
 	clip-empty.c					\
@@ -333,9 +334,10 @@ REFERENCE_IMAGES = \
 	caps-joins-alpha.ref.png	\
 	caps-joins-alpha.svg12.ref.png	\
 	caps-joins-alpha.svg11.ref.png	\
+	caps-joins-curve.ref.png	\
+	caps-joins-curve.ps.ref.png	\
 	caps-joins.ref.png	\
-	caps-joins.ps2.ref.png	\
-	caps-joins.ps3.ref.png	\
+	caps-joins.ps.ref.png	\
 	caps-sub-paths.ref.png	\
 	clip-all.ref.png	\
 	clip-empty.ref.png	\
diff --git a/test/caps-joins-curve.c b/test/caps-joins-curve.c
new file mode 100644
index 0000000..1b2fc7f
--- /dev/null
+++ b/test/caps-joins-curve.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2008 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define LINE_WIDTH	10.
+#define SIZE		(5 * LINE_WIDTH)
+#define PAD		(3 * LINE_WIDTH)
+
+static void
+make_path (cairo_t *cr)
+{
+    cairo_move_to (cr, 0, 0);
+    cairo_rel_curve_to (cr,
+			-SIZE/4, SIZE/3,
+			-SIZE/4, SIZE/3,
+			0, SIZE);
+    cairo_rel_curve_to (cr,
+			SIZE/3, -SIZE/4,
+			SIZE/3, -SIZE/4,
+			SIZE, 0);
+    cairo_close_path (cr);
+
+    cairo_move_to (cr, 5 * LINE_WIDTH, 3 * LINE_WIDTH);
+    cairo_rel_curve_to (cr,
+			0, -3 * LINE_WIDTH,
+			0, -3 * LINE_WIDTH,
+			-3 * LINE_WIDTH, -3 * LINE_WIDTH);
+}
+
+static void
+draw_caps_joins (cairo_t *cr)
+{
+    cairo_save (cr);
+
+    cairo_translate (cr, PAD, PAD);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+    cairo_stroke (cr);
+
+    cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+
+    draw_caps_joins (cr);
+
+    /* and reflect to generate the opposite vertex ordering */
+    cairo_translate (cr, 0, height);
+    cairo_scale (cr, 1, -1);
+
+    draw_caps_joins (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (caps_joins_curve,
+	    "Test caps and joins on curves",
+	    "stroke cap join", /* keywords */
+	    NULL, /* requirements */
+	    3 * (PAD + SIZE) + PAD,
+	    2 * (PAD + SIZE) + PAD,
+	    NULL, draw)
+
diff --git a/test/caps-joins-curve.ps.ref.png b/test/caps-joins-curve.ps.ref.png
new file mode 100644
index 0000000..1f7e200
Binary files /dev/null and b/test/caps-joins-curve.ps.ref.png differ
diff --git a/test/caps-joins-curve.ref.png b/test/caps-joins-curve.ref.png
new file mode 100644
index 0000000..9f76301
Binary files /dev/null and b/test/caps-joins-curve.ref.png differ
diff --git a/test/caps-joins.c b/test/caps-joins.c
index 5ec6a81..9d1c2a8 100644
--- a/test/caps-joins.c
+++ b/test/caps-joins.c
@@ -37,21 +37,15 @@ make_path (cairo_t *cr)
     cairo_rel_line_to (cr, SIZE, 0.);
     cairo_close_path (cr);
 
-    cairo_move_to (cr, 2 * LINE_WIDTH, 0.);
-    cairo_rel_line_to (cr, 3 * LINE_WIDTH, 0.);
-    cairo_rel_line_to (cr, 0., 3 * LINE_WIDTH);
+    cairo_move_to (cr, 5 * LINE_WIDTH, 3 * LINE_WIDTH);
+    cairo_rel_line_to (cr, 0., -3 * LINE_WIDTH);
+    cairo_rel_line_to (cr, -3 * LINE_WIDTH, 0.);
 }
 
-static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
+static void
+draw_caps_joins (cairo_t *cr)
 {
-    /* We draw in the default black, so paint white first. */
     cairo_save (cr);
-    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
-    cairo_paint (cr);
-    cairo_restore (cr);
-
-    cairo_set_line_width (cr, LINE_WIDTH);
 
     cairo_translate (cr, PAD, PAD);
 
@@ -74,6 +68,28 @@ draw (cairo_t *cr, int width, int height)
     cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
     cairo_stroke (cr);
 
+    cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+
+    draw_caps_joins (cr);
+
+    /* and reflect to generate the opposite vertex ordering */
+    cairo_translate (cr, 0, height);
+    cairo_scale (cr, 1, -1);
+
+    draw_caps_joins (cr);
+
     return CAIRO_TEST_SUCCESS;
 }
 
@@ -82,6 +98,6 @@ CAIRO_TEST (caps_joins,
 	    "stroke", /* keywords */
 	    NULL, /* requirements */
 	    3 * (PAD + SIZE) + PAD,
-	    PAD + SIZE + PAD,
+	    2 * (PAD + SIZE) + PAD,
 	    NULL, draw)
 
diff --git a/test/caps-joins.ps.ref.png b/test/caps-joins.ps.ref.png
new file mode 100644
index 0000000..e61aafc
Binary files /dev/null and b/test/caps-joins.ps.ref.png differ
diff --git a/test/caps-joins.ps2.ref.png b/test/caps-joins.ps2.ref.png
deleted file mode 100644
index 1d473ac..0000000
Binary files a/test/caps-joins.ps2.ref.png and /dev/null differ
diff --git a/test/caps-joins.ps3.ref.png b/test/caps-joins.ps3.ref.png
deleted file mode 100644
index 1d473ac..0000000
Binary files a/test/caps-joins.ps3.ref.png and /dev/null differ
diff --git a/test/caps-joins.ref.png b/test/caps-joins.ref.png
index 9297ac4..d83f956 100644
Binary files a/test/caps-joins.ref.png and b/test/caps-joins.ref.png differ
diff --git a/test/dash-curve.ref.png b/test/dash-curve.ref.png
index 542b2d8..a590fc4 100644
Binary files a/test/dash-curve.ref.png and b/test/dash-curve.ref.png differ
commit f39dd86e292e9af3438acb041a3a7330fb4a3b22
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Nov 27 00:23:11 2008 +0000

    [test] Add simple cap test.
    
    Add a test case that only exercises capping, useful for developing
    new strokers.

diff --git a/test/Makefile.am b/test/Makefile.am
index 9534198..7ab086d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,6 +13,7 @@ test_sources = \
 	big-line.c					\
 	big-trap.c					\
 	bilevel-image.c					\
+	caps.c						\
 	caps-joins.c					\
 	caps-joins-alpha.c				\
 	caps-sub-paths.c				\
@@ -326,6 +327,8 @@ REFERENCE_IMAGES = \
 	bilevel-image.ref.png		\
 	bitmap-font.ref.png	\
 	bitmap-font.rgb24.ref.png	\
+	caps.ref.png	\
+	caps.ps.ref.png	\
 	caps-joins-alpha.quartz.ref.png	\
 	caps-joins-alpha.ref.png	\
 	caps-joins-alpha.svg12.ref.png	\
diff --git a/test/caps.c b/test/caps.c
new file mode 100644
index 0000000..7f56117
--- /dev/null
+++ b/test/caps.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright © 2008 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define LINE_WIDTH	10.
+#define SIZE		(5 * LINE_WIDTH)
+#define PAD		(2 * LINE_WIDTH)
+
+static void
+make_path (cairo_t *cr)
+{
+    int i;
+
+    cairo_save (cr);
+    for (i = 0; i <= 3; i++) {
+	cairo_new_sub_path (cr);
+	cairo_move_to (cr, -SIZE / 2, 0.);
+	cairo_line_to (cr,  SIZE / 2, 0.);
+	cairo_rotate (cr, M_PI / 4.);
+    }
+    cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+    cairo_translate (cr, PAD + SIZE / 2., PAD + SIZE / 2.);
+
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+    make_path (cr);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, 0, SIZE + PAD);
+
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+    make_path (cr);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, 0, SIZE + PAD);
+
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+    make_path (cr);
+    cairo_stroke (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (caps,
+	    "Test caps",
+	    "stroke caps", /* keywords */
+	    NULL, /* requirements */
+	    PAD + SIZE + PAD,
+	    3 * (PAD + SIZE) + PAD,
+	    NULL, draw)
+
diff --git a/test/caps.ps.ref.png b/test/caps.ps.ref.png
new file mode 100644
index 0000000..b1f4a72
Binary files /dev/null and b/test/caps.ps.ref.png differ
diff --git a/test/caps.ref.png b/test/caps.ref.png
new file mode 100644
index 0000000..a46e036
Binary files /dev/null and b/test/caps.ref.png differ
commit f2982e103c27cad1edf648dadcfffe1a15763efd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Nov 25 17:23:33 2008 +0000

    [fill] Allow rectangles to be implicitly closed.
    
    Also scan for appendages of simple rectangles.

diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index a6dea08..d37b375 100644
--- a/src/cairo-path-fill.c
+++ b/src/cairo-path-fill.c
@@ -237,7 +237,7 @@ _cairo_path_fixed_fill_rectangle (cairo_path_fixed_t	*path,
 	 * GdkRegion clip region during exposes.
 	 */
 	_cairo_path_fixed_iter_init (&iter, path);
-	while (_cairo_path_fixed_iter_is_box (&iter, &box)) {
+	while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) {
 	    cairo_status_t status;
 	    int cw = 0;
 
diff --git a/src/cairo-path-fixed-private.h b/src/cairo-path-fixed-private.h
index c7a0985..0ade988 100644
--- a/src/cairo-path-fixed-private.h
+++ b/src/cairo-path-fixed-private.h
@@ -99,8 +99,8 @@ _cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter,
 			     cairo_path_fixed_t *path);
 
 cairo_private cairo_bool_t
-_cairo_path_fixed_iter_is_box (cairo_path_fixed_iter_t *_iter,
-			       cairo_box_t *box);
+_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter,
+				    cairo_box_t *box);
 
 cairo_private cairo_bool_t
 _cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter);
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index eee67dc..ba46760 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -1068,8 +1068,8 @@ _cairo_path_fixed_iter_next_op (cairo_path_fixed_iter_t *iter)
 }
 
 cairo_bool_t
-_cairo_path_fixed_iter_is_box (cairo_path_fixed_iter_t *_iter,
-			       cairo_box_t *box)
+_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter,
+				    cairo_box_t *box)
 {
     cairo_point_t points[5];
     cairo_path_fixed_iter_t iter;
@@ -1112,12 +1112,16 @@ _cairo_path_fixed_iter_is_box (cairo_path_fixed_iter_t *_iter,
 
     /* Now, there are choices. The rectangle might end with a LINE_TO
      * (to the original point), but this isn't required. If it
-     * doesn't, then it must end with a CLOSE_PATH. */
-    if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_LINE_TO) {
+     * doesn't, then it must end with a CLOSE_PATH (which may be implicit). */
+    if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_LINE_TO)
+    {
 	points[4] = iter.buf->points[iter.n_point++];
 	if (points[4].x != points[0].x || points[4].y != points[0].y)
 	    return FALSE;
-    } else if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_CLOSE_PATH) {
+    }
+    else if (! (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_CLOSE_PATH ||
+		iter.buf->op[iter.n_op] == CAIRO_PATH_OP_MOVE_TO))
+    {
 	return FALSE;
     }
     if (! _cairo_path_fixed_iter_next_op (&iter))
commit d2bcf1d76defda861e1a7f2271046851083ad694
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 28 17:12:03 2008 +0000

    [path] Carefully check for no more points.
    
    As the empty path points to an embedded buf, we cannot rely on the buf
    pointer being NULL to mark end-of-path.

diff --git a/src/cairo-path-fixed-private.h b/src/cairo-path-fixed-private.h
index c995e2a..c7a0985 100644
--- a/src/cairo-path-fixed-private.h
+++ b/src/cairo-path-fixed-private.h
@@ -54,9 +54,9 @@ typedef char cairo_path_op_t;
 
 typedef struct _cairo_path_buf {
     struct _cairo_path_buf *next, *prev;
-    int buf_size;
-    int num_ops;
-    int num_points;
+    unsigned int buf_size;
+    unsigned int num_ops;
+    unsigned int num_points;
 
     cairo_path_op_t *op;
     cairo_point_t *points;
@@ -90,8 +90,8 @@ _cairo_path_fixed_equal (const cairo_path_fixed_t *a,
 
 typedef struct _cairo_path_fixed_iter {
     cairo_path_buf_t *buf;
-    int n_op;
-    int n_point;
+    unsigned int n_op;
+    unsigned int n_point;
 } cairo_path_fixed_iter_t;
 
 cairo_private void
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index ffaf58c..eee67dc 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -759,7 +759,7 @@ _cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path,
 				    cairo_fixed_t scaley)
 {
     cairo_path_buf_t *buf = &path->buf_head.base;
-    int i;
+    unsigned int i;
 
     while (buf) {
 	 for (i = 0; i < buf->num_points; i++) {
@@ -790,7 +790,7 @@ _cairo_path_fixed_transform (cairo_path_fixed_t	*path,
 			     cairo_matrix_t     *matrix)
 {
     cairo_path_buf_t *buf;
-    int i;
+    unsigned int i;
     double dx, dy;
 
     if (matrix->yx == 0.0 && matrix->xy == 0.0) {
@@ -1058,7 +1058,7 @@ _cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter,
 static cairo_bool_t
 _cairo_path_fixed_iter_next_op (cairo_path_fixed_iter_t *iter)
 {
-    if (++iter->n_op == iter->buf->num_ops) {
+    if (++iter->n_op >= iter->buf->num_ops) {
 	iter->buf = iter->buf->next;
 	iter->n_op = 0;
 	iter->n_point = 0;
@@ -1079,6 +1079,12 @@ _cairo_path_fixed_iter_is_box (cairo_path_fixed_iter_t *_iter,
 
     iter = *_iter;
 
+    if (iter.n_op == iter.buf->num_ops &&
+	! _cairo_path_fixed_iter_next_op (&iter))
+    {
+	return FALSE;
+    }
+
     /* Check whether the ops are those that would be used for a rectangle */
     if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_MOVE_TO)
 	return FALSE;
@@ -1149,6 +1155,9 @@ _cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter)
     if (iter->buf == NULL)
 	return TRUE;
 
+    if (iter->n_op == iter->buf->num_ops)
+	return TRUE;
+
     if (iter->buf->op[iter->n_op] == CAIRO_PATH_OP_MOVE_TO &&
 	iter->buf->num_ops == iter->n_op + 1)
     {
commit 424aba9be558e89b4d42554ca6a5042574e3df75
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Nov 26 20:38:24 2008 +0000

    [check] Search for the word NOTE
    
    Add word boundary markers around the regexp so that we only match for the
    word NOTE and not on substrings like GL_NOTEQUAL.

diff --git a/src/check-doc-syntax.sh b/src/check-doc-syntax.sh
index abf526d..a5c8462 100755
--- a/src/check-doc-syntax.sh
+++ b/src/check-doc-syntax.sh
@@ -64,7 +64,7 @@ if echo $FILES | xargs grep . /dev/null | sed -e '/<programlisting>/,/<\/program
 	echo "	'$func_regexp'"
 fi >&2
 
-note_regexp='NOTE'
+note_regexp='\<NOTE\>'
 if echo $FILES | xargs grep "$note_regexp" /dev/null; then
 	stat=1
 	echo Error: some source files contain the string 'NOTE'.
commit 36147140ce56d8d3492b971a9b6ceff97e212e01
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 28 18:54:02 2008 +0000

    [perf] Fix build
    
    If automake detects the use of cairo_perf_LDADD in an unused conditional
    that overrides the default - so we need to manually set cairo_perf_LDADD.

diff --git a/perf/Makefile.am b/perf/Makefile.am
index 18eed9f..ae39dbc 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -54,9 +54,10 @@ else
 cairo_perf_SOURCES += cairo-perf-posix.c
 endif
 endif
+cairo_perf_LDADD = $(LDADD)
 
 if CAIRO_HAS_SDL_SURFACE
-cairo_perf_LDADD = $(LDADD) $(sdl_LIBS)
+cairo_perf_LDADD += $(sdl_LIBS)
 endif
 
 libcairoperf_la_SOURCES = \


More information about the cairo-commit mailing list