diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-18 17:26:55 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-29 11:20:34 +0000 |
commit | e6963a5bfebda69a1ef0a986cede84bcd955b6d4 (patch) | |
tree | a70bd8d15c60a71ba88bdf299244f93aa7b147d0 | |
parent | d1801c23fae3777c7c59e084894a3410f7a1f932 (diff) |
Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are
extremely unlikely.
54 files changed, 300 insertions, 294 deletions
diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c index 9fb19a87..a19ff10c 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 ef50684f..9c084b9e 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 4d5a4652..9d42ef48 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 eca28d5b..cd150218 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 73172642..07c8b71f 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 2d1fd8fd..d1e5a6dd 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 5c197fff..35082f94 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 3bb884ca..863189f4 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 8cbd3bcd..cab7104c 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 06377588..a78c2aab 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 a8d41013..773f6ea0 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 d7d91c90..09161aa4 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 b3f43b05..973281d4 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 008ba7fd..a699a524 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 ab8ab5ed..2bf45430 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 c1791765..a4fdf738 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 f32f4893..e69df21c 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 c4876031..6f707a66 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 780bd50c..71154339 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 70b728ea..2b58e499 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 04d547ca..2f365624 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 f2b9e7ae..8c3064ea 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 855b85fe..84dfc0c4 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 56fa28a5..aa580d55 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 9d5bcba1..ea5c5148 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 9926e6ff..b85a6c82 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 21ed8e35..4158f175 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 69df0f3e..301a8921 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 95cadc9c..0b0fa991 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 43219e5b..9d2a7c5c 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 146ae60b..53a359b3 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 a1b4c22c..c802c314 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 76572a54..ca86f512 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 fc3164d7..77a9e5f5 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 800ad83a..d98566d5 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 02e15565..d03a6bfc 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 3bc234e9..edc4f889 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 bb80538f..8e6e2687 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 a6c97f23..dff8d9f0 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 35e256fd..8b66662d 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 a8717029..0afdce23 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 b3a48151..4662eaa3 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 d54215de..91c00542 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 a62a2613..fe74dc6c 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 7106040f..ebc78dd2 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 5e2077f3..6670b536 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 2823e5dc..e85174b7 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 1878f8e7..3b1ae2e1 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 75d4de3f..0e915132 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 f6eb1ee9..7dbe86c2 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 924f7caa..75674f98 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 883941df..d20e7c94 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 71700bdd..6ac1803e 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 cfb87f33..58d5b0a7 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)); } |