mi: 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:
parent
7752d8450d
commit
bdcf8d200f
16
mi/miarc.c
16
mi/miarc.c
|
@ -1191,9 +1191,9 @@ miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count, /* number of points */
|
|||
y = ymax - ymin + 1;
|
||||
if ((count < 3) || (y <= 0))
|
||||
return;
|
||||
ptsOut = FirstPoint = xallocarray(y, sizeof(DDXPointRec));
|
||||
width = FirstWidth = xallocarray(y, sizeof(int));
|
||||
Marked = xallocarray(count, sizeof(int));
|
||||
ptsOut = FirstPoint = calloc(y, sizeof(DDXPointRec));
|
||||
width = FirstWidth = calloc(y, sizeof(int));
|
||||
Marked = calloc(count, sizeof(int));
|
||||
|
||||
if (!ptsOut || !width || !Marked) {
|
||||
free(Marked);
|
||||
|
@ -1893,10 +1893,10 @@ miComputeArcs(xArc * parcs, int narcs, GCPtr pGC)
|
|||
isDoubleDash = (pGC->lineStyle == LineDoubleDash);
|
||||
dashOffset = pGC->dashOffset;
|
||||
|
||||
data = xallocarray(narcs, sizeof(struct arcData));
|
||||
data = calloc(narcs, sizeof(struct arcData));
|
||||
if (!data)
|
||||
return NULL;
|
||||
arcs = xallocarray(isDoubleDash ? 2 : 1, sizeof(*arcs));
|
||||
arcs = calloc(isDoubleDash ? 2 : 1, sizeof(*arcs));
|
||||
if (!arcs) {
|
||||
free(data);
|
||||
return NULL;
|
||||
|
@ -3083,8 +3083,8 @@ fillSpans(DrawablePtr pDrawable, GCPtr pGC)
|
|||
|
||||
if (nspans == 0)
|
||||
return;
|
||||
xSpan = xSpans = xallocarray(nspans, sizeof(DDXPointRec));
|
||||
xWidth = xWidths = xallocarray(nspans, sizeof(int));
|
||||
xSpan = xSpans = calloc(nspans, sizeof(DDXPointRec));
|
||||
xWidth = xWidths = calloc(nspans, sizeof(int));
|
||||
if (xSpans && xWidths) {
|
||||
i = 0;
|
||||
f = finalSpans;
|
||||
|
@ -3138,7 +3138,7 @@ realFindSpan(int y)
|
|||
else
|
||||
change = SPAN_REALLOC;
|
||||
newSize = finalSize + change;
|
||||
newSpans = xallocarray(newSize, sizeof(struct finalSpan *));
|
||||
newSpans = calloc(newSize, sizeof(struct finalSpan *));
|
||||
if (!newSpans)
|
||||
return NULL;
|
||||
newMiny = finalMiny;
|
||||
|
|
|
@ -467,9 +467,9 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
|
|||
ndepth++;
|
||||
nvisual += visuals->count;
|
||||
}
|
||||
depth = xallocarray(ndepth, sizeof(DepthRec));
|
||||
visual = xallocarray(nvisual, sizeof(VisualRec));
|
||||
preferredCVCs = xallocarray(ndepth, sizeof(int));
|
||||
depth = calloc(ndepth, sizeof(DepthRec));
|
||||
visual = calloc(nvisual, sizeof(VisualRec));
|
||||
preferredCVCs = calloc(ndepth, sizeof(int));
|
||||
if (!depth || !visual || !preferredCVCs) {
|
||||
free(depth);
|
||||
free(visual);
|
||||
|
@ -490,7 +490,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
|
|||
prefp++;
|
||||
vid = NULL;
|
||||
if (nvtype) {
|
||||
vid = xallocarray(nvtype, sizeof(VisualID));
|
||||
vid = calloc(nvtype, sizeof(VisualID));
|
||||
if (!vid) {
|
||||
free(depth);
|
||||
free(visual);
|
||||
|
|
|
@ -60,7 +60,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
|
|||
|
||||
if (nbox > 1) {
|
||||
/* keep ordering in each band, reverse order of bands */
|
||||
pboxNew1 = xallocarray(nbox, sizeof(BoxRec));
|
||||
pboxNew1 = calloc(nbox, sizeof(BoxRec));
|
||||
if (!pboxNew1)
|
||||
return;
|
||||
pboxBase = pboxNext = pbox + nbox - 1;
|
||||
|
@ -91,7 +91,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
|
|||
|
||||
if (nbox > 1) {
|
||||
/* reverse order of rects in each band */
|
||||
pboxNew2 = xallocarray(nbox, sizeof(BoxRec));
|
||||
pboxNew2 = calloc(nbox, sizeof(BoxRec));
|
||||
if (!pboxNew2) {
|
||||
free(pboxNew1);
|
||||
return;
|
||||
|
|
|
@ -519,7 +519,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
|
|||
regionnumrects = RegionNumRects(prgn);
|
||||
if (regionnumrects == 0)
|
||||
return;
|
||||
prect = xallocarray(regionnumrects, sizeof(xRectangle));
|
||||
prect = calloc(regionnumrects, sizeof(xRectangle));
|
||||
if (!prect)
|
||||
return;
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ miPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y, unsigned int ngly
|
|||
gcvals);
|
||||
|
||||
nbyLine = BitmapBytePad(width);
|
||||
pbits = xallocarray(height, nbyLine);
|
||||
pbits = calloc(height, nbyLine);
|
||||
if (!pbits) {
|
||||
dixDestroyPixmap(pPixmap, 0);
|
||||
FreeScratchGC(pGCtmp);
|
||||
|
|
|
@ -410,8 +410,8 @@ miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
|
|||
dy = ymax - ymin + 1;
|
||||
if ((count < 3) || (dy < 0))
|
||||
return TRUE;
|
||||
ptsOut = FirstPoint = xallocarray(dy, sizeof(DDXPointRec));
|
||||
width = FirstWidth = xallocarray(dy, sizeof(int));
|
||||
ptsOut = FirstPoint = calloc(dy, sizeof(DDXPointRec));
|
||||
width = FirstWidth = calloc(dy, sizeof(int));
|
||||
if (!FirstPoint || !FirstWidth) {
|
||||
free(FirstWidth);
|
||||
free(FirstPoint);
|
||||
|
|
|
@ -65,7 +65,7 @@ miPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, /* Origin or Previous */
|
|||
int i;
|
||||
xPoint *ppt;
|
||||
|
||||
if (!(pwidthInit = xallocarray(npt, sizeof(int))))
|
||||
if (!(pwidthInit = calloc(npt, sizeof(int))))
|
||||
return;
|
||||
|
||||
/* make pointlist origin relative */
|
||||
|
|
|
@ -86,7 +86,7 @@ miPolyRectangle(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
|
|||
offset2 = pGC->lineWidth;
|
||||
offset1 = offset2 >> 1;
|
||||
offset3 = offset2 - offset1;
|
||||
tmp = xallocarray(ntmp, sizeof(xRectangle));
|
||||
tmp = calloc(ntmp, sizeof(xRectangle));
|
||||
if (!tmp)
|
||||
return;
|
||||
t = tmp;
|
||||
|
|
|
@ -443,8 +443,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
|
|||
ylength = spanGroup->ymax - ymin + 1;
|
||||
|
||||
/* Allocate Spans for y buckets */
|
||||
yspans = xallocarray(ylength, sizeof(Spans));
|
||||
ysizes = xallocarray(ylength, sizeof(int));
|
||||
yspans = calloc(ylength, sizeof(Spans));
|
||||
ysizes = calloc(ylength, sizeof(int));
|
||||
|
||||
if (!yspans || !ysizes) {
|
||||
free(yspans);
|
||||
|
@ -511,8 +511,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
|
|||
} /* for i thorough Spans */
|
||||
|
||||
/* Now sort by x and uniquify each bucket into the final array */
|
||||
points = xallocarray(count, sizeof(DDXPointRec));
|
||||
widths = xallocarray(count, sizeof(int));
|
||||
points = calloc(count, sizeof(DDXPointRec));
|
||||
widths = calloc(count, sizeof(int));
|
||||
if (!points || !widths) {
|
||||
for (i = 0; i < ylength; i++) {
|
||||
free(yspans[i].points);
|
||||
|
@ -559,10 +559,10 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
|
|||
static Bool
|
||||
InitSpans(Spans * spans, size_t nspans)
|
||||
{
|
||||
spans->points = xallocarray(nspans, sizeof(*spans->points));
|
||||
spans->points = calloc(nspans, sizeof(*spans->points));
|
||||
if (!spans->points)
|
||||
return FALSE;
|
||||
spans->widths = xallocarray(nspans, sizeof(*spans->widths));
|
||||
spans->widths = calloc(nspans, sizeof(*spans->widths));
|
||||
if (!spans->widths) {
|
||||
free(spans->points);
|
||||
return FALSE;
|
||||
|
|
|
@ -671,7 +671,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
|
|||
numPts = maxPts << 2;
|
||||
dospans = (pGC->fillStyle != FillSolid);
|
||||
if (dospans) {
|
||||
widths = xallocarray(numPts, sizeof(int));
|
||||
widths = calloc(numPts, sizeof(int));
|
||||
if (!widths)
|
||||
return;
|
||||
maxw = 0;
|
||||
|
@ -687,7 +687,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
|
|||
(unsigned char *) pGC->dash, (int) pGC->numInDashList,
|
||||
&dinfo.dashOffsetInit);
|
||||
}
|
||||
points = xallocarray(numPts, sizeof(DDXPointRec));
|
||||
points = calloc(numPts, sizeof(DDXPointRec));
|
||||
if (!points) {
|
||||
if (dospans) {
|
||||
free(widths);
|
||||
|
|
|
@ -148,8 +148,8 @@ miZeroLine(DrawablePtr pDraw, GCPtr pGC, int mode, /* Origin or Previous */
|
|||
width = xright - xleft + 1;
|
||||
height = ybottom - ytop + 1;
|
||||
list_len = (height >= width) ? height : width;
|
||||
pspanInit = xallocarray(list_len, sizeof(DDXPointRec));
|
||||
pwidthInit = xallocarray(list_len, sizeof(int));
|
||||
pspanInit = calloc(list_len, sizeof(DDXPointRec));
|
||||
pwidthInit = calloc(list_len, sizeof(int));
|
||||
if (!pspanInit || !pwidthInit) {
|
||||
free(pspanInit);
|
||||
free(pwidthInit);
|
||||
|
|
Loading…
Reference in New Issue