]> granicus.if.org Git - graphviz/commitdiff
selectedLayer: rephrase a switch into if-else
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Jun 2022 17:24:19 +0000 (10:24 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Jun 2022 17:24:19 +0000 (10:24 -0700)
This is easier to understand, less code, and squashes a -Wswitch-default
compiler warning.

lib/common/emit.c

index 9ca44f424de29d4132371cac17c2b7733e65f005..281a8eb8ac06bd1e3141e7ce4c9acbfc0453ccdc 100644 (file)
@@ -1051,15 +1051,7 @@ static bool selectedLayer(GVC_t *gvc, int layerNum, int numLayers, char *spec)
        w1 = w0 = strtok_r (cur, gvc->layerDelims, &buf_p);
        if (w0)
            w1 = strtok_r (NULL, gvc->layerDelims, &buf_p);
-       switch ((w0 != NULL) + (w1 != NULL)) {
-       case 0:
-           rval = false;
-           break;
-       case 1:
-           n0 = layer_index(gvc, w0, layerNum);
-           rval = (n0 == layerNum);
-           break;
-       case 2:
+       if (w0 != NULL && w1 != NULL) {
            n0 = layer_index(gvc, w0, 0);
            n1 = layer_index(gvc, w1, numLayers);
            if (n0 >= 0 || n1 >= 0) {
@@ -1070,7 +1062,11 @@ static bool selectedLayer(GVC_t *gvc, int layerNum, int numLayers, char *spec)
                }
                rval = BETWEEN(n0, layerNum, n1);
            }
-           break;
+       } else if (w0 != NULL || w1 != NULL) {
+           n0 = layer_index(gvc, w0, layerNum);
+           rval = (n0 == layerNum);
+       } else {
+           rval = false;
        }
        part_in_p = NULL;
     }