From e67faf530b5c86de91f476a1d17918d2dd08f466 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 23 Sep 2014 12:06:52 +0100 Subject: [PATCH] Rework create_metric_result function. --- src/libmime/filter.c | 15 ++++++++------- src/libmime/filter.h | 9 +++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libmime/filter.c b/src/libmime/filter.c index bdddffb59..d26f26e1d 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -62,12 +62,18 @@ filter_error_quark (void) return g_quark_from_static_string ("g-filter-error-quark"); } -static struct metric_result * +struct metric_result * create_metric_result (struct rspamd_task *task, const gchar *name) { struct metric_result *metric_res; struct metric *metric; + metric_res = g_hash_table_lookup (task->results, name); + + if (metric_res != NULL) { + return metric_res; + } + metric = g_hash_table_lookup (task->cfg->metrics, name); if (metric == NULL) { return NULL; @@ -104,12 +110,7 @@ insert_metric_result (struct rspamd_task *task, gdouble *weight, w; const ucl_object_t *mobj, *sobj; - metric_res = g_hash_table_lookup (task->results, metric->name); - - if (metric_res == NULL) { - /* Create new metric chain */ - metric_res = create_metric_result (task, metric->name); - } + metric_res = create_metric_result (task, metric->name); weight = g_hash_table_lookup (metric->symbols, symbol); if (weight == NULL) { diff --git a/src/libmime/filter.h b/src/libmime/filter.h index 24b871efe..f1f128f63 100644 --- a/src/libmime/filter.h +++ b/src/libmime/filter.h @@ -78,6 +78,15 @@ struct rspamd_composite { gint id; }; +/** + * Create or return existing result for the specified metric name + * @param task task object + * @param name name of metric + * @return metric result or NULL if metric `name` has not been found + */ +struct metric_result * create_metric_result (struct rspamd_task *task, + const gchar *name); + /** * Process all filters * @param task worker's task that present message from user -- 2.39.5