diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-12-11 11:24:05 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-12-11 11:24:05 +0100 |
commit | 79e09b2bf8167e281beab0115ea280914f428919 (patch) | |
tree | e1bb443f38eb63d24867783b811fee9095037510 /grammar/rainerscript.c | |
parent | b49e20f0912f77dc9f4e3b849b11aed5d915a7d8 (diff) | |
download | rsyslog-79e09b2bf8167e281beab0115ea280914f428919.tar.gz rsyslog-79e09b2bf8167e281beab0115ea280914f428919.tar.bz2 rsyslog-79e09b2bf8167e281beab0115ea280914f428919.zip |
script optimizer: optimize and/or on PRI filters
Diffstat (limited to 'grammar/rainerscript.c')
-rw-r--r-- | grammar/rainerscript.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 413964d6..5d68d944 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -153,6 +153,21 @@ prifiltInvert(struct funcData_prifilt *prifilt) } } +/* combine a prifilt with AND/OR (the respective token values are + * used to keep things simple). + */ +static void +prifiltCombine(struct funcData_prifilt *prifilt, struct funcData_prifilt *prifilt2, int mode) +{ + int i; + for(i = 0 ; i < LOG_NFACILITIES+1 ; ++i) { + if(mode == AND) + prifilt->pmask[i] = prifilt->pmask[i] & prifilt2->pmask[i]; + else + prifilt->pmask[i] = prifilt->pmask[i] | prifilt2->pmask[i]; + } +} + void readConfFile(FILE *fp, es_str_t **str) @@ -2447,6 +2462,27 @@ cnfexprOptimize_NOT(struct cnfexpr *expr) return expr; } +static inline struct cnfexpr* +cnfexprOptimize_AND_OR(struct cnfexpr *expr) +{ + struct cnffunc *funcl, *funcr; + + if(expr->l->nodetype == 'F') { + if(expr->r->nodetype == 'F') { + funcl = (struct cnffunc *)expr->l; + funcr = (struct cnffunc *)expr->r; + if(funcl->fID == CNFFUNC_PRIFILT && funcr->fID == CNFFUNC_PRIFILT) { + DBGPRINTF("optimize combine AND/OR prifilt()\n"); + expr->l = NULL; + prifiltCombine(funcl->funcdata, funcr->funcdata, expr->nodetype); + cnfexprDestruct(expr); + expr = (struct cnfexpr*) funcl; + } + } + } + return expr; +} + /* (recursively) optimize an expression */ struct cnfexpr* cnfexprOptimize(struct cnfexpr *expr) @@ -2511,6 +2547,7 @@ cnfexprOptimize(struct cnfexpr *expr) case OR:/* keep recursion goin' on... */ expr->l = cnfexprOptimize(expr->l); expr->r = cnfexprOptimize(expr->r); + expr = cnfexprOptimize_AND_OR(expr); break; case NOT:/* keep recursion goin' on... */ expr->r = cnfexprOptimize(expr->r); |