exa: replace xallocarray() by calloc()

Only key difference that calloc(), in contrast to rellocarray(),
is zero-initializing. The overhead is hard to measure on today's
machines, and it's safer programming practise to always allocate
zero-initialized, so one can't forget to do it explicitly.

Cocci rule:

    @@
    expression COUNT;
    expression LEN;
    @@
    - xallocarray(COUNT,LEN)
    + calloc(COUNT,LEN)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-02-24 12:15:01 +01:00
parent e025b8c805
commit 8e80caa6f7
3 changed files with 8 additions and 8 deletions

View File

@ -384,7 +384,7 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y); exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y);
exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y); exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y);
rects = xallocarray(nbox, sizeof(xRectangle)); rects = calloc(nbox, sizeof(xRectangle));
if (rects) { if (rects) {
int i; int i;
@ -624,7 +624,7 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return; return;
} }
prect = xallocarray(npt, sizeof(xRectangle)); prect = calloc(npt, sizeof(xRectangle));
for (i = 0; i < npt; i++) { for (i = 0; i < npt; i++) {
prect[i].x = ppt[i].x; prect[i].x = ppt[i].x;
prect[i].y = ppt[i].y; prect[i].y = ppt[i].y;
@ -665,7 +665,7 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return; return;
} }
prect = xallocarray(npt - 1, sizeof(xRectangle)); prect = calloc(npt - 1, sizeof(xRectangle));
x1 = ppt[0].x; x1 = ppt[0].x;
y1 = ppt[0].y; y1 = ppt[0].y;
/* If we have any non-horizontal/vertical, fall back. */ /* If we have any non-horizontal/vertical, fall back. */
@ -736,7 +736,7 @@ exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
} }
} }
prect = xallocarray((unsigned int)nseg, sizeof(xRectangle)); prect = calloc((unsigned int)nseg, sizeof(xRectangle));
for (i = 0; i < nseg; i++) { for (i = 0; i < nseg; i++) {
if (pSeg[i].x1 < pSeg[i].x2) { if (pSeg[i].x1 < pSeg[i].x2) {
prect[i].x = pSeg[i].x1; prect[i].x = pSeg[i].x1;

View File

@ -209,8 +209,8 @@ exaRealizeGlyphCaches(ScreenPtr pScreen, unsigned int format)
cache->picture = pPicture; cache->picture = pPicture;
cache->picture->refcnt++; cache->picture->refcnt++;
cache->hashEntries = xallocarray(cache->hashSize, sizeof(int)); cache->hashEntries = calloc(cache->hashSize, sizeof(int));
cache->glyphs = xallocarray(cache->size, sizeof(ExaCachedGlyphRec)); cache->glyphs = calloc(cache->size, sizeof(ExaCachedGlyphRec));
cache->glyphCount = 0; cache->glyphCount = 0;
if (!cache->hashEntries || !cache->glyphs) if (!cache->hashEntries || !cache->glyphs)

View File

@ -203,7 +203,7 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
/* Do we need to allocate our system buffer? */ /* Do we need to allocate our system buffer? */
if (!pExaPixmap->sys_ptr) { if (!pExaPixmap->sys_ptr) {
pExaPixmap->sys_ptr = xallocarray(pExaPixmap->sys_pitch, pExaPixmap->sys_ptr = calloc(pExaPixmap->sys_pitch,
pPixmap->drawable.height); pPixmap->drawable.height);
if (!pExaPixmap->sys_ptr) if (!pExaPixmap->sys_ptr)
FatalError("EXA: malloc failed for size %d bytes\n", FatalError("EXA: malloc failed for size %d bytes\n",