From deee51a5ff278ce5d623344af8035a5c425464bf 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 2e6aba7a4..2f3ffc38a 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -435,41 +435,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 = calloc(ndepth, sizeof(DepthRec)); - visual = calloc(nvisual, sizeof(VisualRec)); - preferredCVCs = calloc(ndepth, sizeof(int)); + + DepthPtr depth = calloc(ndepth, sizeof(DepthRec)); + VisualPtr visual = calloc(nvisual, sizeof(VisualRec)); + int *preferredCVCs = calloc(ndepth, sizeof(int)); if (!depth || !visual || !preferredCVCs) { free(depth); free(visual); @@ -480,15 +470,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 = calloc(nvtype, sizeof(VisualID)); if (!vid) { @@ -501,7 +493,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; @@ -541,6 +532,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp, vid++; visual++; } + depth++; free(visuals); } miVisuals = NULL; @@ -553,7 +545,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) {