summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-09-25 13:01:36 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-09-25 13:01:36 +0200
commit6b9457c4d73f9732645094d2efed85e02b1f9d03 (patch)
treed613027c6875b2455b2683599acb3aed39f71b6f /grammar
parent39b9aac66390eab4a7a9c0898744363a61cd4457 (diff)
downloadrsyslog-6b9457c4d73f9732645094d2efed85e02b1f9d03.tar.gz
rsyslog-6b9457c4d73f9732645094d2efed85e02b1f9d03.tar.xz
rsyslog-6b9457c4d73f9732645094d2efed85e02b1f9d03.zip
Implement Script Optimizer: remove always-true PRIFILT
Diffstat (limited to 'grammar')
-rw-r--r--grammar/rainerscript.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index d3e82fae..b8edf991 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -51,6 +51,7 @@ DEFobjCurrIf(obj)
DEFobjCurrIf(regexp)
void cnfexprOptimize(struct cnfexpr *expr);
+static void cnfstmtOptimizePRIFilt(struct cnfstmt *stmt);
char*
getFIOPName(unsigned iFIOP)
@@ -2087,11 +2088,11 @@ cnfstmtOptimizeIf(struct cnfstmt *stmt)
stmt->printable = (uchar*)
es_str2cstr(((struct cnfstringval*)func->expr[0])->estr, NULL);
cnfexprDestruct(expr);
+ cnfstmtOptimizePRIFilt(stmt);
}
}
}
-
static inline void
cnfstmtOptimizeAct(struct cnfstmt *stmt)
{
@@ -2105,6 +2106,46 @@ cnfstmtOptimizeAct(struct cnfstmt *stmt)
}
}
+static void
+cnfstmtOptimizePRIFilt(struct cnfstmt *stmt)
+{
+ int i;
+ int isAlways = 1;
+ struct cnfstmt *subroot, *last;
+
+ stmt->d.s_prifilt.t_then = removeNOPs(stmt->d.s_prifilt.t_then);
+ cnfstmtOptimize(stmt->d.s_prifilt.t_then);
+
+ for(i = 0; i <= LOG_NFACILITIES; i++)
+ if(stmt->d.s_prifilt.pmask[i] != 0xff) {
+ isAlways = 0;
+ break;
+ }
+ if(!isAlways)
+ goto done;
+
+ DBGPRINTF("optimizer: removing always-true PRIFILT %p\n", stmt);
+ if(stmt->d.s_prifilt.t_else != NULL) {
+ parser_errmsg("error: always-true PRI filter has else part!\n");
+ // TODO: enable (requires changes in action.c) cnfstmtDestruct(stmt->d.s_prifilt.t_else);
+ }
+ subroot = stmt->d.s_prifilt.t_then;
+ if(subroot == NULL) {
+ /* very strange, we set it to NOP, best we can do
+ * This case is NOT expected in practice
+ */
+ stmt->nodetype = S_NOP;
+ goto done;
+ }
+ for(last = subroot ; last->next != NULL ; last = last->next)
+ /* find last node in subtree */;
+ last->next = stmt->next;
+ memcpy(stmt, subroot, sizeof(struct cnfstmt));
+ free(subroot);
+
+done: return;
+}
+
/* (recursively) optimize a statement */
void
cnfstmtOptimize(struct cnfstmt *root)
@@ -2118,8 +2159,7 @@ dbgprintf("RRRR: stmtOptimize: stmt %p, nodetype %u\n", stmt, stmt->nodetype);
cnfstmtOptimizeIf(stmt);
break;
case S_PRIFILT:
- stmt->d.s_prifilt.t_then = removeNOPs(stmt->d.s_prifilt.t_then);
- cnfstmtOptimize(stmt->d.s_prifilt.t_then);
+ cnfstmtOptimizePRIFilt(stmt);
break;
case S_PROPFILT:
stmt->d.s_propfilt.t_then = removeNOPs(stmt->d.s_propfilt.t_then);
@@ -2143,7 +2183,7 @@ dbgprintf("RRRR: stmtOptimize: stmt %p, nodetype %u\n", stmt, stmt->nodetype);
break;
}
}
-done: /*EMPTY*/;
+done: return;
}