]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Move group-by value and label getting code into helper functions
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Thu, 5 Mar 2020 13:22:53 +0000 (15:22 +0200)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Fri, 13 Mar 2020 08:25:17 +0000 (08:25 +0000)
This avoids some excessive indentation.

src/stats/stats-metrics.c

index dcdcb0fd5954621ffb4316f210e8147cb44867a5..09abc91470952f1cfa07e2e560a31e13977b6e16 100644 (file)
@@ -435,6 +435,41 @@ stats_metric_group_by_quantized_label(const struct event_field *field,
        return label;
 }
 
+static bool
+stats_metric_group_by_get_value(const struct event_field *field,
+                               const struct stats_metric_settings_group_by *group_by,
+                               struct metric_value *value)
+{
+       switch (group_by->func) {
+       case STATS_METRIC_GROUPBY_DISCRETE:
+               if (!stats_metric_group_by_discrete(field, value))
+                       return FALSE;
+               return TRUE;
+       case STATS_METRIC_GROUPBY_QUANTIZED:
+               if (!stats_metric_group_by_quantized(field, value, group_by))
+                       return FALSE;
+               return TRUE;
+       }
+
+       i_panic("unknown group-by function %d", group_by->func);
+}
+
+static const char *
+stats_metric_group_by_get_label(const struct event_field *field,
+                               const struct stats_metric_settings_group_by *group_by,
+                               const struct metric_value *value)
+{
+       switch (group_by->func) {
+       case STATS_METRIC_GROUPBY_DISCRETE:
+               i_unreached();
+       case STATS_METRIC_GROUPBY_QUANTIZED:
+               return stats_metric_group_by_quantized_label(field, group_by,
+                                                            value->intmax);
+       }
+
+       i_panic("unknown group-by function %d", group_by->func);
+}
+
 static void
 stats_metric_group_by(struct metric *metric, struct event *event, pool_t pool)
 {
@@ -447,16 +482,8 @@ stats_metric_group_by(struct metric *metric, struct event *event, pool_t pool)
        if (field == NULL)
                return;
 
-       switch (group_by->func) {
-       case STATS_METRIC_GROUPBY_DISCRETE:
-               if (!stats_metric_group_by_discrete(field, &value))
-                       return;
-               break;
-       case STATS_METRIC_GROUPBY_QUANTIZED:
-               if (!stats_metric_group_by_quantized(field, &value, group_by))
-                       return;
-               break;
-       }
+       if (!stats_metric_group_by_get_value(field, group_by, &value))
+               return;
 
        if (!array_is_created(&metric->sub_metrics))
                p_array_init(&metric->sub_metrics, pool, 8);
@@ -474,15 +501,9 @@ stats_metric_group_by(struct metric *metric, struct event *event, pool_t pool)
                        value_label = dec2str(field->value.intmax);
                        break;
                case METRIC_VALUE_TYPE_BUCKET_INDEX:
-                       switch (group_by->func) {
-                       case STATS_METRIC_GROUPBY_DISCRETE:
-                               i_unreached();
-                       case STATS_METRIC_GROUPBY_QUANTIZED:
-                               value_label = stats_metric_group_by_quantized_label(field,
-                                                                                   group_by,
-                                                                                   value.intmax);
-                               break;
-                       }
+                       value_label = stats_metric_group_by_get_label(field,
+                                                                     group_by,
+                                                                     &value);
                        break;
                }