[cairo] [PATCH] Fix _cairo_region_get_boxes usage

Soeren Sandmann sandmann at daimi.au.dk
Sun Feb 15 00:01:06 PST 2009

Jeff Muizelaar <jeff at infidigm.net> writes:

> Chris,
> The attached patch fixes some issues with callers of
> _cairo_region_get_boxes. The new api seems a little bit difficult to
> use and I'm wondering if we can fix it at all? Though I don't really have any
> ideas or know if it's worth it. Thoughts?

As far as I can tell, all code that uses the get_boxes() interface do
so because they want to iterate through the boxes once and do
something with each. None of them actually store the array
anywhere. So how about adding a:

        _cairo_region_get_box (cairo_region_t *region, 
                               int nth_box,
                               cairo_int_box_t *box)

to allow callers to do:

        n_boxes = cairo_region_num_boxes (region);
        for (i = 0; i < n_boxes; ++i)
                cairo_int_box_t box;
                cairo_region_get_box (region, i, &box);

                <do something with box>

That completely avoids memory allocation while making the interface
much simpler.

(For extra efficiency the get_box() call could return a pointer to a
const box. That would avoid the copying, but introduce an unpleasant
dependency on the region's lifetime, so it's probably not worth it).


More information about the cairo mailing list