From e0b9e65a09ebaa0d94b80b1504a2d285186125e3 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 31 Jan 2013 17:36:16 +0000 Subject: Add some 'restrict' qualifiers to hopefully speed matrix ops. Also, move fz_is_infinite_rect and fz_is_empty_rect to be a static inline rather than a macro. (Static inlines are preferred over macros by at least one customers). We appear to be calling them with bboxes too, so add fz_is_infinite_bbox and fz_is_empty_bbox to solve this. --- fitz/base_geometry.c | 30 +++++++++++++++--------------- fitz/fitz.h | 26 +++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 18 deletions(-) (limited to 'fitz') diff --git a/fitz/base_geometry.c b/fitz/base_geometry.c index 8b9cf4c8..cc69a108 100644 --- a/fitz/base_geometry.c +++ b/fitz/base_geometry.c @@ -243,7 +243,7 @@ fz_matrix_max_expansion(const fz_matrix *m) } fz_point * -fz_transform_point(fz_point *p, const fz_matrix *m) +fz_transform_point(fz_point *restrict p, const fz_matrix *restrict m) { float x = p->x; p->x = x * m->a + p->y * m->c + m->e; @@ -252,7 +252,7 @@ fz_transform_point(fz_point *p, const fz_matrix *m) } fz_point * -fz_transform_vector(fz_point *p, const fz_matrix *m) +fz_transform_vector(fz_point *restrict p, const fz_matrix *restrict m) { float x = p->x; p->x = x * m->a + p->y * m->c; @@ -275,7 +275,7 @@ const fz_bbox fz_empty_bbox = { 0, 0, 0, 0 }; const fz_bbox fz_unit_bbox = { 0, 0, 1, 1 }; fz_bbox * -fz_bbox_from_rect(fz_bbox *b, const fz_rect *r) +fz_bbox_from_rect(fz_bbox *restrict b, const fz_rect *restrict r) { int i; @@ -292,7 +292,7 @@ fz_bbox_from_rect(fz_bbox *b, const fz_rect *r) } fz_rect * -fz_rect_from_bbox(fz_rect *r, const fz_bbox *a) +fz_rect_from_bbox(fz_rect *restrict r, const fz_bbox *restrict a) { r->x0 = a->x0; r->y0 = a->y0; @@ -302,7 +302,7 @@ fz_rect_from_bbox(fz_rect *r, const fz_bbox *a) } fz_bbox * -fz_round_rect(fz_bbox *b, const fz_rect *r) +fz_round_rect(fz_bbox * restrict b, const fz_rect *restrict r) { int i; @@ -319,7 +319,7 @@ fz_round_rect(fz_bbox *b, const fz_rect *r) } fz_rect * -fz_intersect_rect(fz_rect *a, const fz_rect *b) +fz_intersect_rect(fz_rect *restrict a, const fz_rect *restrict b) { /* Check for empty box before infinite box */ if (fz_is_empty_rect(a)) return a; @@ -346,17 +346,17 @@ fz_intersect_rect(fz_rect *a, const fz_rect *b) } fz_bbox * -fz_intersect_bbox(fz_bbox *a, const fz_bbox *b) +fz_intersect_bbox(fz_bbox *restrict a, const fz_bbox *restrict b) { /* Check for empty box before infinite box */ - if (fz_is_empty_rect(a)) return a; - if (fz_is_empty_rect(b)) + if (fz_is_empty_bbox(a)) return a; + if (fz_is_empty_bbox(b)) { *a = fz_empty_bbox; return a; } - if (fz_is_infinite_rect(b)) return a; - if (fz_is_infinite_rect(a)) + if (fz_is_infinite_bbox(b)) return a; + if (fz_is_infinite_bbox(a)) { *a = *b; return a; @@ -375,7 +375,7 @@ fz_intersect_bbox(fz_bbox *a, const fz_bbox *b) } fz_rect * -fz_union_rect(fz_rect *a, const fz_rect *b) +fz_union_rect(fz_rect *restrict a, const fz_rect *restrict b) { /* Check for empty box before infinite box */ if (fz_is_empty_rect(b)) return a; @@ -404,8 +404,8 @@ fz_translate_bbox(fz_bbox *a, int xoff, int yoff) { int t; - if (fz_is_empty_rect(a)) return a; - if (fz_is_infinite_rect(a)) return a; + if (fz_is_empty_bbox(a)) return a; + if (fz_is_infinite_bbox(a)) return a; a->x0 = ADD_WITH_SAT(t, a->x0, xoff); a->y0 = ADD_WITH_SAT(t, a->y0, yoff); a->x1 = ADD_WITH_SAT(t, a->x1, xoff); @@ -414,7 +414,7 @@ fz_translate_bbox(fz_bbox *a, int xoff, int yoff) } fz_rect * -fz_transform_rect(fz_rect *r, const fz_matrix *m) +fz_transform_rect(fz_rect *restrict r, const fz_matrix *restrict m) { fz_point s, t, u, v; diff --git a/fitz/fitz.h b/fitz/fitz.h index 926943f6..9fe3597e 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -805,7 +805,17 @@ extern const fz_bbox fz_infinite_bbox; An empty rectangle is defined as one whose area is zero. */ -#define fz_is_empty_rect(r) ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1) +static inline int +fz_is_empty_rect(const fz_rect *r) +{ + return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); +} + +static inline int +fz_is_empty_bbox(const fz_bbox *r) +{ + return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); +} /* fz_is_infinite: Check if rectangle is infinite. @@ -813,7 +823,17 @@ extern const fz_bbox fz_infinite_bbox; An infinite rectangle is defined as one where either of the two relationships between corner coordinates are not true. */ -#define fz_is_infinite_rect(r) ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1) +static inline int +fz_is_infinite_rect(const fz_rect *r) +{ + return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); +} + +static inline int +fz_is_infinite_bbox(const fz_bbox *r) +{ + return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); +} /* fz_matrix is a a row-major 3x3 matrix used for representing @@ -840,7 +860,7 @@ struct fz_matrix_s */ extern const fz_matrix fz_identity; -static inline fz_matrix *fz_copy_matrix(fz_matrix *m, const fz_matrix *s) +static inline fz_matrix *fz_copy_matrix(fz_matrix *restrict m, const fz_matrix *restrict s) { *m = *s; return m; -- cgit v1.2.3