mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-01 22:20:14 +01:00
[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.
This commit is contained in:
parent
e0187ad49b
commit
e82b0f46b2
1 changed files with 25 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue