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

Enrico Weigelt, metux IT consult enrico.weigelt at gr13.net
Mon Apr 17 16:56:49 UTC 2017


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 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



More information about the cairo mailing list