From ca5c59282d2f3bdbf48e8a0997f2b04dc346198c Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 18 Sep 2024 14:52:59 +0200 Subject: [PATCH] mi: miInitVisuals: clean up variable declarations The code is easier to understand when variables are declared where they're used for the first time, scoped to where they're needed and not reused for separate things. Signed-off-by: Enrico Weigelt, metux IT consult --- mi/micmap.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/mi/micmap.c b/mi/micmap.c index 1259bbba2..a5fb204b8 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -433,41 +433,31 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, unsigned long sizes, int bitsPerRGB, int preferredVis) { int i, j = 0, k; - VisualPtr visual; - DepthPtr depth; - VisualID *vid; - int d, b; int f; - int ndepth, nvisual; - int nvtype; - int vtype; miVisualsPtr visuals, nextVisuals; - int *preferredCVCs, *prefp; - int first_depth; /* none specified, we'll guess from pixmap formats */ if (!miVisuals) { for (f = 0; f < screenInfo.numPixmapFormats; f++) { - d = screenInfo.formats[f].depth; - b = screenInfo.formats[f].bitsPerPixel; - if (sizes & (1 << (b - 1))) - vtype = miGetDefaultVisualMask(d); - else - vtype = 0; + int d = screenInfo.formats[f].depth; + int b = screenInfo.formats[f].bitsPerPixel; + int vtype = ((sizes & (1 << (b - 1))) ? miGetDefaultVisualMask(d) : 0); if (!miSetVisualTypes(d, vtype, bitsPerRGB, -1)) return FALSE; } } - nvisual = 0; - ndepth = 0; + + int nvisual = 0; + int ndepth = 0; for (visuals = miVisuals; visuals; visuals = nextVisuals) { nextVisuals = visuals->next; ndepth++; nvisual += visuals->count; } - depth = xallocarray(ndepth, sizeof(DepthRec)); - visual = xallocarray(nvisual, sizeof(VisualRec)); - preferredCVCs = xallocarray(ndepth, sizeof(int)); + + DepthPtr depth = xallocarray(ndepth, sizeof(DepthRec)); + VisualPtr visual = xallocarray(nvisual, sizeof(VisualRec)); + int *preferredCVCs = xallocarray(ndepth, sizeof(int)); if (!depth || !visual || !preferredCVCs) { free(depth); free(visual); @@ -478,15 +468,17 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, *visualp = visual; *ndepthp = ndepth; *nvisualp = nvisual; - prefp = preferredCVCs; + + int *prefp = preferredCVCs; for (visuals = miVisuals; visuals; visuals = nextVisuals) { + int d = visuals->depth; + int vtype = visuals->visuals; + int nvtype = visuals->count; + nextVisuals = visuals->next; - d = visuals->depth; - vtype = visuals->visuals; - nvtype = visuals->count; + VisualID *vid = NULL; *prefp = visuals->preferredCVC; prefp++; - vid = NULL; if (nvtype) { vid = xallocarray(nvtype, sizeof(VisualID)); if (!vid) { @@ -499,7 +491,6 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, depth->depth = d; depth->numVids = nvtype; depth->vids = vid; - depth++; for (i = 0; i < NUM_PRIORITY; i++) { if (!(vtype & (1 << miVisualPriority[i]))) continue; @@ -534,6 +525,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, vid++; visual++; } + depth++; free(visuals); } miVisuals = NULL; @@ -546,7 +538,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, * structures - if there is, we want to start looking for the * default visual/depth from that depth. */ - first_depth = 0; + int first_depth = 0; if (preferredVis < 0 && defaultColorVisualClass < 0) { for (i = 0; i < ndepth; i++) { if (preferredCVCs[i] >= 0) {