]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Use a switch instead of if/else-if
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Tue, 18 Feb 2020 18:27:23 +0000 (13:27 -0500)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Fri, 13 Mar 2020 08:25:17 +0000 (08:25 +0000)
The compiler will then warn about unchecked enum values.

src/stats/stats-metrics.c

index 869e1a78350a08c2ae65226b361b6cd4f6f36753..03b4a4168c5dc4fef5f79e3d25fdd08e68cc9b13 100644 (file)
@@ -319,13 +319,17 @@ stats_metric_get_sub_metric(struct metric *metric,
 
        /* lookup sub-metric */
        array_foreach (&metric->sub_metrics, sub_metrics) {
-               if ((*sub_metrics)->group_value.type == METRIC_VALUE_TYPE_STR &&
-                   memcmp((*sub_metrics)->group_value.hash, value->hash,
-                          SHA1_RESULTLEN) == 0)
-                       return *sub_metrics;
-               else if ((*sub_metrics)->group_value.type == METRIC_VALUE_TYPE_INT &&
-                   (*sub_metrics)->group_value.intmax == value->intmax)
-                       return *sub_metrics;
+               switch ((*sub_metrics)->group_value.type) {
+               case METRIC_VALUE_TYPE_STR:
+                       if (memcmp((*sub_metrics)->group_value.hash, value->hash,
+                                  SHA1_RESULTLEN) == 0)
+                               return *sub_metrics;
+                       break;
+               case METRIC_VALUE_TYPE_INT:
+                       if ((*sub_metrics)->group_value.intmax == value->intmax)
+                               return *sub_metrics;
+                       break;
+               }
        }
        return NULL;
 }
@@ -394,13 +398,17 @@ stats_metric_group_by(struct metric *metric, struct event *event, pool_t pool)
        sub_metric = stats_metric_get_sub_metric(metric, &value);
 
        if (sub_metric == NULL) T_BEGIN {
-               const char *value_label;
-               if (value.type == METRIC_VALUE_TYPE_STR)
+               const char *value_label = NULL;
+
+               switch (value.type) {
+               case METRIC_VALUE_TYPE_STR:
                        value_label = field->value.str;
-               else if (value.type == METRIC_VALUE_TYPE_INT)
+                       break;
+               case METRIC_VALUE_TYPE_INT:
                        value_label = dec2str(field->value.intmax);
-               else
-                       i_unreached();
+                       break;
+               }
+
                sub_metric = stats_metric_sub_metric_alloc(metric, value_label,
                                                           pool);
                if (metric->group_by_count > 1) {