From 849e4aa8e6437cbfb6efbc7379414fcf517e6db9 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 3 Jul 2011 18:19:32 +0200 Subject: grammar: small optimization during expr creation --- grammar/mini.samp | 2 +- grammar/utils.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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; } -- cgit