[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [RFC PATCH 1/6] util: Add API for converting virBitmap into printable string



> > +    for ( ; sz > 0; sz--)
> > +        virBufferVSprintf(&buf, "%08x", bitmap->map[sz - 1]);
> 
> I probably would have written:
> 
> while (sz--)
>     virBufferVSprintf(&buf, "%08x", bitmap->map[sz]);

Yeah, it looks nicer; I'll use that since I'll send a new version anyway.

> since sz is guaranteed to be non-zero to start with.  But your way
> works, and the compiler (hopefully) generates the same code (when
> optimizing).

Not that this is in a performance critical path requiring any optimizations
:-)

> Problem - "%08x" is not portable.  bitmap->map[x] is a uint32_t, which
> means we need to use "%08"PRIx32 (since some platforms declare uint32_t
> as long rather than int) to avoid a gcc warning.

Ah, thanks for spotting that. I always forget about this dark side of C.

> For that matter, why did we make the bitset use uint32_t as the
> underlying type, instead of just using long?

Right, I'll fix that first followed by a v2 of this patch.

Jirka


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]