Use ARRAY_SIZE all over the tree

Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Daniel Martin 2017-10-27 16:11:56 +02:00 • committed by Adam Jackson
commit d5379b350f
44 changed files with 66 additions and 105 deletions

View file

@ -655,9 +655,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS));
len += btlen * 4; /* buttonmask len */
vallen =
count_bits(ev->valuators.mask,
sizeof(ev->valuators.mask) / sizeof(ev->valuators.mask[0]));
vallen = count_bits(ev->valuators.mask, ARRAY_SIZE(ev->valuators.mask));
len += vallen * 2 * sizeof(uint32_t); /* axisvalues */
vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */

View file

@ -439,7 +439,7 @@ ChangeGCXIDs(ClientPtr client, GC * pGC, BITS32 mask, CARD32 *pC32)
}
for (i = Ones(mask); i--;)
vals[i].val = pC32[i];
for (i = 0; i < sizeof(xidfields) / sizeof(*xidfields); ++i) {
for (i = 0; i < ARRAY_SIZE(xidfields); ++i) {
int offset, rc;
if (!(mask & xidfields[i].mask))

View file

@ -571,8 +571,6 @@ static const int offsets[] = {
offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
};
#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0]))
int
dixLookupPrivateOffset(RESTYPE type)
{
@ -587,7 +585,7 @@ dixLookupPrivateOffset(RESTYPE type)
return offsets[RT_PIXMAP & TypeMask];
}
type = type & TypeMask;
if (type < NUM_OFFSETS)
if (type < ARRAY_SIZE(offsets))
return offsets[type];
return -1;
}