David,

I am not sure what the difference is between your changes and the original code. I thought you wanted to optimize the code by simplifying evaluation process as I described below. Am I missing something?

//for LogicalAnd
boolean left = ((Boolean) _lhsExp.evaluate()).booleanValue();
if (!left) return Boolean(false) //no further evaluation



//for LogicalOr
boolean left = ((Boolean) _lhsExp.evaluate()).booleanValue();
if (left) return Boolean(true) //no further evaluation


In addition, the left hand side or the right hand side can be a constant expression, so a constant expression can always be eliminated when a logical expression is created.

Xiping


Inactive hide details for dawood@apache.orgdawood@apache.org


          dawood@apache.org

          05/28/2009 05:18 PM
          Please respond to
          imperius-dev@incubator.apache.org


To

imperius-commits@incubator.apache.org

cc


Subject

svn commit: r779776 - in /incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl: LogicalAnd.java LogicalOr.java

Author: dawood
Date: Thu May 28 21:18:43 2009
New Revision: 779776

URL:
http://svn.apache.org/viewvc?rev=779776&view=rev
Log:
implement short-circuited evaluation.

Modified:
   incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalAnd.java
   incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalOr.java

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalAnd.java
URL:
http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalAnd.java?rev=779776&r1=779775&r2=779776&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalAnd.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalAnd.java Thu May 28 21:18:43 2009
@@ -76,7 +76,7 @@
        try
        {
            boolean left = ((Boolean) _lhsExp.evaluate()).booleanValue();
-            boolean right = ((Boolean) _rhsExp.evaluate()).booleanValue();
+            boolean right = left && ((Boolean) _rhsExp.evaluate()).booleanValue();

            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
         

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalOr.java
URL:
http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalOr.java?rev=779776&r1=779775&r2=779776&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalOr.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/LogicalOr.java Thu May 28 21:18:43 2009
@@ -79,7 +79,7 @@
        {
           //System.out.println("Logical OR::LHS type: RHS type ::"+ lhsExp.getType() + ":" + rhsExp.getType());
            boolean left = ((Boolean) _lhsExp.evaluate()).booleanValue();
-            boolean right = ((Boolean) _rhsExp.evaluate()).booleanValue();
+            boolean right = left || ((Boolean) _rhsExp.evaluate()).booleanValue();
           //System.out.println("Logical OR::after Evaluation LHS: RHS ::"+ left + ":" + right);
            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");