Browse code

core expr eval: minor ==/!= optimization

- replace the generic RVE_EQ_OP/RVE_DIFF_OP with the type specific
version (RVE_IEQ_OP/RVE_STREQ_OP...), if the type is known.

Andrei Pelinescu-Onciul authored on 28/04/2009 15:49:54
Showing 1 changed files
... ...
@@ -2341,10 +2341,10 @@ static int rve_op_is_commutative(enum rval_expr_op op, enum rval_type type)
2341 2341
 		case RVE_GTE_OP:
2342 2342
 		case RVE_LT_OP:
2343 2343
 		case RVE_LTE_OP:
2344
-		case RVE_EQ_OP:
2344
+		case RVE_CONCAT_OP:
2345 2345
 			return 0;
2346 2346
 		case RVE_DIFF_OP:
2347
-		case RVE_CONCAT_OP:
2347
+		case RVE_EQ_OP:
2348 2348
 #if !defined(UNDEF_EQ_ALWAYS_FALSE) && !defined(UNDEF_EQ_UNDEF_TRUE)
2349 2349
 			return 1;
2350 2350
 #else
... ...
@@ -2838,6 +2838,25 @@ static int rve_optimize(struct rval_expr* rve)
2838 2838
 						rve->fpos.e_line, rve->fpos.e_col);
2839 2839
 			}
2840 2840
 		}
2841
+		/* e1 EQ_OP e2 -> change op if we know e1 basic type
2842
+		   e1 DIFF_OP e2 -> change op if we know e2 basic type */
2843
+		if (rve->op==RVE_EQ_OP || rve->op==RVE_DIFF_OP){
2844
+			l_type=rve_guess_type(rve->left.rve);
2845
+			if (l_type==RV_INT){
2846
+				rve->op=(rve->op==RVE_EQ_OP)?RVE_IEQ_OP:RVE_IDIFF_OP;
2847
+				DBG("FIXUP RVE (%d,%d-%d,%d): changed ==/!= into interger"
2848
+						" ==/!=\n",
2849
+						rve->fpos.s_line, rve->fpos.s_col,
2850
+						rve->fpos.e_line, rve->fpos.e_col);
2851
+			}else if (l_type==RV_STR){
2852
+				rve->op=RVE_CONCAT_OP;
2853
+				rve->op=(rve->op==RVE_EQ_OP)?RVE_STREQ_OP:RVE_STRDIFF_OP;
2854
+				DBG("FIXUP RVE (%d,%d-%d,%d): changed ==/!= into string"
2855
+						" ==/!=\n",
2856
+						rve->fpos.s_line, rve->fpos.s_col,
2857
+						rve->fpos.e_line, rve->fpos.e_col);
2858
+			}
2859
+		}
2841 2860
 		
2842 2861
 		/* $v * 0 => 0; $v * 1 => $v (for *, /, &, |, &&, ||, +, -) */
2843 2862
 		if (rve_opt_01(rve, type)==1){