[cairo] Using bit fields a bit more in cairo
behdad at behdad.org
Tue Dec 19 15:23:58 PST 2006
On Tue, 2006-12-19 at 16:59 -0500, Carl Worth wrote:
> On Tue, 19 Dec 2006 13:36:26 -0800, Carl Worth wrote:
> > I originally started writing this email because I thought this was a
> > feature of C we weren't using in cairo yet. But now I do notice that
> > pixman is already using bit fields. So I don't foresee any problem
> > here. Some of the problems of bit fields that prevent their use in
> > some circumstances, (such as no guarantee of packing order), aren't
> > relevant here where we're just using flags and don't care about the
> > order.
> By the way, there's another potential nuisance with bit fields that I
> think is actually a good thing. With a single flags approach, (single
> integer manipulated with masks), it's much easier to initialize all
> the bits at once:
> path->flags = 0;
> or to copy the flags:
> path->flags = other->flags;
> compared with flag-by-flag initialization and copying required for bit
> path->has_current_point = 0;
> path->has_curve_to = 0;
> path->has_current_point = other->has_current_point;
> path->has_curve_to = other->curve_to;
> So that looks like a nuisance in the bit field approach, but it's
> actually a big advantage.
All agreed. I don't see any reason not to use bitfields. We use them
in Pango in public api and never had any problem that I know of.
"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759
More information about the cairo