[SR-Dev] git:andrei/script_vars: script engine: optimize $v - ct

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Dec 18 17:00:55 CET 2008


Module: sip-router
Branch: andrei/script_vars
Commit: 73f4a76ec264fdad4921c4ba26ecb1f6dadc81e9
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=73f4a76ec264fdad4921c4ba26ecb1f6dadc81e9

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Dec 18 09:45:06 2008 +0100

script engine: optimize $v - ct

- $v - ct transformed into $v + (-ct) which is easier to optimize
  further

---

 rvalue.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/rvalue.c b/rvalue.c
index 063be00..558ab70 100644
--- a/rvalue.c
+++ b/rvalue.c
@@ -1992,7 +1992,24 @@ static int rve_optimize(struct rval_expr* rve)
 					rval_type_name(bad_type), rval_type_name(exp_type));
 			return 0;
 		}
-		/* TODO: $v - a => $v + (-a) */
+		/* $v - a => $v + (-a)  (easier to optimize)*/
+		if ((rve->op==RVE_MINUS_OP) && (rve_is_constant(rve->right.rve))){
+			if ((rv=rval_expr_eval(0, 0, rve->right.rve))==0){
+				ERR("optimization failure, bad expression\n");
+				goto error;
+			}
+			if (rv->type==RV_INT){
+				rv->v.l=-rv->v.l;
+				if (rve_replace_with_ct_rv(rve->right.rve, rv)<0)
+					goto error;
+				rve->op=RVE_PLUS_OP;
+				DBG("FIXUP RVE: optimized $v - a into $v + (%d)\n",
+								(int)rve->right.rve->left.rval.v.l);
+			}
+			rval_destroy(rv);
+			rv=0;
+		}
+		
 		/* TODO: $v * 0 => 0; $v * 1 => $v (for *, /, &, |, &&, ||, +, -) */
 		
 		/* op(op($v, a), b) => op($v, op(a,b)) */




More information about the sr-dev mailing list