[cairo-commit] src/cairoint.h src/cairo-polygon.c
Chris Wilson
ickle at kemper.freedesktop.org
Thu Sep 18 01:27:19 PDT 2008
src/cairo-polygon.c | 71 +++++++++++++++-------------------------------------
src/cairoint.h | 14 ++++------
2 files changed, 27 insertions(+), 58 deletions(-)
New commits:
commit 0ab14a6b218097721535e1d6d9b3341b7336bb70
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Sep 18 09:04:01 2008 +0100
[polygon] Reduce number of branches.
Minimise the number of conditionals taken whilst constructing the polygon.
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 1653f95..1392bfa 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -36,11 +36,6 @@
#include "cairoint.h"
-/* private functions */
-
-static cairo_status_t
-_cairo_polygon_grow (cairo_polygon_t *polygon);
-
void
_cairo_polygon_init (cairo_polygon_t *polygon)
{
@@ -57,31 +52,17 @@ _cairo_polygon_init (cairo_polygon_t *polygon)
void
_cairo_polygon_fini (cairo_polygon_t *polygon)
{
- if (polygon->edges && polygon->edges != polygon->edges_embedded)
+ if (polygon->edges != polygon->edges_embedded)
free (polygon->edges);
-
- polygon->edges = NULL;
- polygon->edges_size = 0;
- polygon->num_edges = 0;
-
- polygon->has_current_point = FALSE;
-}
-
-cairo_status_t
-_cairo_polygon_status (cairo_polygon_t *polygon)
-{
- return polygon->status;
}
/* make room for at least one more edge */
-static cairo_status_t
+static cairo_bool_t
_cairo_polygon_grow (cairo_polygon_t *polygon)
{
cairo_edge_t *new_edges;
int old_size = polygon->edges_size;
- int new_size = 2 * old_size;
-
- assert (polygon->num_edges <= polygon->edges_size);
+ int new_size = 4 * old_size;
if (polygon->edges == polygon->edges_embedded) {
new_edges = _cairo_malloc_ab (new_size, sizeof (cairo_edge_t));
@@ -92,34 +73,34 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
new_size, sizeof (cairo_edge_t));
}
- if (new_edges == NULL)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ if (new_edges == NULL) {
+ polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ return FALSE;
+ }
polygon->edges = new_edges;
polygon->edges_size = new_size;
- return CAIRO_STATUS_SUCCESS;
+ return TRUE;
}
-void
-_cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_point_t *p2)
+static void
+_cairo_polygon_add_edge (cairo_polygon_t *polygon,
+ const cairo_point_t *p1,
+ const cairo_point_t *p2)
{
cairo_edge_t *edge;
- if (polygon->status)
- return;
-
/* drop horizontal edges */
if (p1->y == p2->y)
goto DONE;
- if (polygon->num_edges >= polygon->edges_size) {
- polygon->status = _cairo_polygon_grow (polygon);
- if (polygon->status)
+ if (polygon->num_edges == polygon->edges_size) {
+ if (! _cairo_polygon_grow (polygon))
return;
}
- edge = &polygon->edges[polygon->num_edges];
+ edge = &polygon->edges[polygon->num_edges++];
if (p1->y < p2->y) {
edge->edge.p1 = *p1;
edge->edge.p2 = *p2;
@@ -130,18 +111,14 @@ _cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_poin
edge->clockWise = 0;
}
- polygon->num_edges++;
-
DONE:
_cairo_polygon_move_to (polygon, p2);
}
void
-_cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point)
+_cairo_polygon_move_to (cairo_polygon_t *polygon,
+ const cairo_point_t *point)
{
- if (polygon->status)
- return;
-
if (! polygon->has_current_point)
polygon->first_point = *point;
@@ -150,24 +127,18 @@ _cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point)
}
void
-_cairo_polygon_line_to (cairo_polygon_t *polygon, cairo_point_t *point)
+_cairo_polygon_line_to (cairo_polygon_t *polygon,
+ const cairo_point_t *point)
{
- if (polygon->status)
- return;
-
- if (polygon->has_current_point) {
+ if (polygon->has_current_point)
_cairo_polygon_add_edge (polygon, &polygon->current_point, point);
- } else {
+ else
_cairo_polygon_move_to (polygon, point);
- }
}
void
_cairo_polygon_close (cairo_polygon_t *polygon)
{
- if (polygon->status)
- return;
-
if (polygon->has_current_point) {
_cairo_polygon_add_edge (polygon,
&polygon->current_point,
diff --git a/src/cairoint.h b/src/cairoint.h
index 1a6697d..0f10bd8 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2084,21 +2084,19 @@ _cairo_polygon_init (cairo_polygon_t *polygon);
cairo_private void
_cairo_polygon_fini (cairo_polygon_t *polygon);
-cairo_private cairo_status_t
-_cairo_polygon_status (cairo_polygon_t *polygon);
-
cairo_private void
-_cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_point_t *p2);
+_cairo_polygon_move_to (cairo_polygon_t *polygon,
+ const cairo_point_t *point);
cairo_private void
-_cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point);
-
-cairo_private void
-_cairo_polygon_line_to (cairo_polygon_t *polygon, cairo_point_t *point);
+_cairo_polygon_line_to (cairo_polygon_t *polygon,
+ const cairo_point_t *point);
cairo_private void
_cairo_polygon_close (cairo_polygon_t *polygon);
+#define _cairo_polygon_status(P) (P)->status
+
/* cairo-spline.c */
cairo_private cairo_int_status_t
_cairo_spline_init (cairo_spline_t *spline,
More information about the cairo-commit
mailing list