aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-27 00:02:48 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-27 00:02:48 +0000
commit3728212eeea755b5a71e38a9e8dbd832ba3b4b19 (patch)
tree43426a2e847c76b7eec3804a1db53c66ef1a56e6 /src/libutil
parent6607a24cc8b050497cedf5a20c17d9e2950da68b (diff)
downloadrspamd-3728212eeea755b5a71e38a9e8dbd832ba3b4b19.tar.gz
rspamd-3728212eeea755b5a71e38a9e8dbd832ba3b4b19.zip
More to priorities optimization.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/expression.c20
-rw-r--r--src/libutil/expression.h2
2 files changed, 18 insertions, 4 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index a668371cc..c18783d79 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -392,13 +392,14 @@ rspamd_ast_priority_traverse (GNode *node, gpointer d)
if (elt->type == ELT_LIMIT) {
/* Always push limit first */
- elt->priority = G_MAXINT;
+ elt->priority = 0;
}
else {
- elt->priority = 0;
+ elt->priority = RSPAMD_EXPRESSION_MAX_PRIORITY;
if (expr->subr->priority != NULL) {
- elt->priority = expr->subr->priority (elt->p.atom);
+ elt->priority = RSPAMD_EXPRESSION_MAX_PRIORITY -
+ expr->subr->priority (elt->p.atom);
}
}
}
@@ -411,7 +412,7 @@ rspamd_ast_priority_cmp (GNode *a, GNode *b)
{
struct rspamd_expression_elt *ea = a->data, *eb = b->data;
- return eb->priority - ea->priority;
+ return ea->priority - eb->priority;
}
static gboolean
@@ -991,6 +992,8 @@ static gboolean
rspamd_ast_string_traverse (GNode *n, gpointer d)
{
GString *res = d;
+ gint cnt;
+ GNode *cur;
struct rspamd_expression_elt *elt = n->data;
const char *op_str = NULL;
@@ -1034,6 +1037,15 @@ rspamd_ast_string_traverse (GNode *n, gpointer d)
break;
}
g_string_append (res, op_str);
+
+ if (n->children) {
+ LL_COUNT(n->children, cur, cnt);
+
+ if (cnt > 2) {
+ /* Print n-ary of the operator */
+ g_string_append_printf (res, "(%d)", cnt);
+ }
+ }
}
g_string_append_c (res, ' ');
diff --git a/src/libutil/expression.h b/src/libutil/expression.h
index 8605bbbda..924dbb45b 100644
--- a/src/libutil/expression.h
+++ b/src/libutil/expression.h
@@ -28,6 +28,8 @@
#include "config.h"
#include "mem_pool.h"
+#define RSPAMD_EXPRESSION_MAX_PRIORITY 1024
+
typedef struct rspamd_expression_atom_s {
/* Opaque userdata */
gpointer data;