[cairo-commit] 2 commits - src/cairo-path-fixed.c
Chris Wilson
ickle at kemper.freedesktop.org
Thu Dec 27 06:52:30 PST 2007
src/cairo-path-fixed.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
New commits:
commit e82b0f46b2ea6ebcee5ea5cc09e9ab5c6cc383fb
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Nov 14 00:45:24 2007 +0000
[cairo-path-fixed] Consolidate cairo_path_buf_t when copying.
When copying the cairo_path_fixed_t, consolidate the list of
dynamically allocated cairo_path_buf_t into a single buffer.
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index cd5527e..e18ecc3 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -91,6 +91,7 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
cairo_path_fixed_t *other)
{
cairo_path_buf_t *buf, *other_buf;
+ unsigned int num_points, num_ops, buf_size;
_cairo_path_fixed_init (path);
@@ -106,21 +107,37 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
other->buf_head.base.num_ops * sizeof (other->buf_head.op[0]));
memcpy (path->buf_head.points, other->buf_head.points,
other->buf_head.base.num_points * sizeof (other->buf_head.points[0]));
+
+ num_points = num_ops = 0;
for (other_buf = other->buf_head.base.next;
- other_buf;
+ other_buf != NULL;
other_buf = other_buf->next)
{
- buf = _cairo_path_buf_create (other_buf->buf_size);
+ num_ops += other_buf->num_ops;
+ num_points += other_buf->num_points;
+ }
+
+ buf_size = MAX (num_ops, (num_points + 1) / 2);
+ if (buf_size) {
+ buf = _cairo_path_buf_create (buf_size);
if (buf == NULL) {
_cairo_path_fixed_fini (path);
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
- buf->num_ops = other_buf->num_ops;
- buf->num_points = other_buf->num_points;
- memcpy (buf->op, other_buf->op,
- buf->num_ops * sizeof (buf->op[0]));
- memcpy (buf->points, other_buf->points,
- buf->num_points * sizeof (buf->points[0]));
+
+ for (other_buf = other->buf_head.base.next;
+ other_buf != NULL;
+ other_buf = other_buf->next)
+ {
+ memcpy (buf->op + buf->num_ops, other_buf->op,
+ other_buf->num_ops * sizeof (buf->op[0]));
+ buf->num_ops += other_buf->num_ops;
+
+ memcpy (buf->points + buf->num_points, other_buf->points,
+ other_buf->num_points * sizeof (buf->points[0]));
+ buf->num_points += other_buf->num_points;
+ }
+
_cairo_path_fixed_add_buf (path, buf);
}
commit e0187ad49b754c4024f1999155ed248616028582
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Dec 27 12:46:13 2007 +0000
[cairo-path-fixed] Ensure the points array is naturally aligned, take 2.
By enlarging buf_size to ensure the correct alignment of the points
array with the cairo_path_buf_t block, we can efficiently use the
padding bytes to store more ops.
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index d485364..cd5527e 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -404,12 +404,13 @@ _cairo_path_buf_create (int buf_size)
{
cairo_path_buf_t *buf;
-#define align(ptr__, alignment__) \
- ((void *) (((long) (ptr__) + (alignment__) - 1) & -(alignment__)))
+ /* adjust buf_size to ensure that buf->points is naturally aligned */
+ buf_size += sizeof (double)
+ - ((buf_size + sizeof (cairo_path_buf_t)) & (sizeof (double)-1));
buf = _cairo_malloc_ab_plus_c (buf_size,
sizeof (cairo_path_op_t) +
2 * sizeof (cairo_point_t),
- sizeof (cairo_path_buf_t) + sizeof (double));
+ sizeof (cairo_path_buf_t));
if (buf) {
buf->next = NULL;
buf->prev = NULL;
@@ -417,10 +418,9 @@ _cairo_path_buf_create (int buf_size)
buf->num_points = 0;
buf->buf_size = buf_size;
- buf->points = (cairo_point_t *) align (buf + 1, sizeof (double));
- buf->op = (cairo_path_op_t *) (buf->points + 2 * buf_size);
+ buf->op = (cairo_path_op_t *) (buf + 1);
+ buf->points = (cairo_point_t *) (buf->op + buf_size);
}
-#undef align
return buf;
}
More information about the cairo-commit
mailing list