summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-03 18:19:32 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-03 18:19:32 +0200
commit849e4aa8e6437cbfb6efbc7379414fcf517e6db9 (patch)
treee2cfd32148b40f6cad97e8500b3c84a0367bd2e8
parent719962c1f0f1ee1a6d5b5389417fb68adcde431b (diff)
downloadrsyslog-849e4aa8e6437cbfb6efbc7379414fcf517e6db9.tar.gz
rsyslog-849e4aa8e6437cbfb6efbc7379414fcf517e6db9.tar.xz
rsyslog-849e4aa8e6437cbfb6efbc7379414fcf517e6db9.zip
grammar: small optimization during expr creation
-rw-r--r--grammar/mini.samp2
-rw-r--r--grammar/utils.c9
2 files changed, 10 insertions, 1 deletions
diff --git a/grammar/mini.samp b/grammar/mini.samp
index 6aae758d..9e00b7cf 100644
--- a/grammar/mini.samp
+++ b/grammar/mini.samp
@@ -24,7 +24,7 @@ if 1 then { /var/log/log3
@@fwd
rger
}
-if 2*4/5--(10-3)/*pri("*.*")*/ then {
+if 2*4/-5--(10-3)/*pri("*.*")*/ then {
action(type="omfile" taget="/var/log/log5")
action(type="omfile" taget="/var/log/log6")
action(type="omfwd" taget="10.0.0.1" port="514")
diff --git a/grammar/utils.c b/grammar/utils.c
index c26a856c..bc300aaf 100644
--- a/grammar/utils.c
+++ b/grammar/utils.c
@@ -233,11 +233,20 @@ struct cnfexpr*
cnfexprNew(int nodetype, struct cnfexpr *l, struct cnfexpr *r)
{
struct cnfexpr *expr;
+
+ /* optimize some constructs during parsing */
+ if(nodetype == 'M' && r->nodetype == 'N') {
+ ((struct cnfnumval*)r)->val *= -1;
+ expr = r;
+ goto done;
+ }
+
if((expr = malloc(sizeof(struct cnfexpr))) != NULL) {
expr->nodetype = nodetype;
expr->l = l;
expr->r = r;
}
+done:
return expr;
}