[cairo] [PATCH 12/72] core: helper funtion for initializing rects with zero

Chris Wilson chris at chris-wilson.co.uk
Tue Dec 29 06:19:30 PST 2015


On Tue, Dec 29, 2015 at 10:16:50AM +0100, Enrico Weigelt, metux IT consult wrote:
> In some places we zero-out rects field-by-field.
> 
> On one hand we should encapsulate that in a helper, to make the source
> a bit easier to read, and to have it all in one place, in case of
> possible later changes.
> 
> OTOH, use static zero initializer instead of explicit field-by-field,
> to allow the compiler to use vector ops and so save a few cycles
> on certain cpu archs.
> 
> Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
> ---
>  src/cairo-path-bounds.c | 3 +--
>  src/cairoint.h          | 6 ++++++
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cairo-path-bounds.c b/src/cairo-path-bounds.c
> index 624b3cb..6dcf90c 100644
> --- a/src/cairo-path-bounds.c
> +++ b/src/cairo-path-bounds.c
> @@ -144,8 +144,7 @@ _cairo_path_fixed_fill_extents (const cairo_path_fixed_t	*path,
>  	path->extents.p1.y < path->extents.p2.y) {
>  	_cairo_box_round_to_rectangle (&path->extents, extents);
>      } else {
> -	extents->x = extents->y = 0;
> -	extents->width = extents->height = 0;
> +	_cairo_zero_rectangle_init (extents);
>      }
>  }
>  
> diff --git a/src/cairoint.h b/src/cairoint.h
> index f781748..b8d66bd 100644
> --- a/src/cairoint.h
> +++ b/src/cairoint.h
> @@ -327,6 +327,12 @@ _cairo_unbounded_rectangle_init (cairo_rectangle_int_t *rect)
>      *rect = _cairo_unbounded_rectangle;
>  }
>  
> +static inline void
> +_cairo_zero_rectangle_init (cairo_rectangle_int_t *rect)
> +{
> +    *rect = (cairo_rectangle_int_t){ 0 };
> +}

Anonymous structs are not available on all the compilers we support (we
expect to still compile on old school SunOS!)
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list