Re: [PATCH 10/71] core: helper funtion for initializing rects with zero

Bryce Harrington <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On Mon, Apr 17, 2017 at 06:56:49PM +0200, 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.

Unless there are other places where _cairo_zero_rectangle_init() can be
used (I couldn't find any), just set extents to {0} directly.

If we had a convention for init routines that zero out structs it might
be worth it, but adding a routine for creating a degenerate rect seems
unnecessary.
 
> 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.

If this is a measurable optimization, there could be additional spots in
the code where this approach could be beneficial, although I'm only
finding places where structs are *mostly* zero with a few members set to
other values (e.g. cairo_matrix_init).

> Signed-off-by: Enrico Weigelt, metux IT consult <[email protected]>
> ---
>  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 624b3cb4d..6dcf90cf1 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 493d46103..d83481632 100644
> --- a/src/cairoint.h
> +++ b/src/cairoint.h
> @@ -333,6 +333,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 };
> +}
> +
>  cairo_private_no_warn cairo_bool_t
>  _cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
>  			    const cairo_rectangle_int_t *src);
> -- 
> 2.11.0.rc0.7.gbe5a750
> 
> -- 
> cairo mailing list
> [email protected]
> https://lists.cairographics.org/mailman/listinfo/cairo
-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.