incubator-imperius-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xiping Wang <xip...@us.ibm.com>
Subject Re: svn commit: r779776 - in /incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl: LogicalAnd.java LogicalOr.java
Date Fri, 29 May 2009 14:39:26 GMT

I guess I didn't look at it carefully, sorry. ^_^  You probably also want
to make a change to the last line (return new Boolean(left && right);) in
that block.

Xiping



                                                                           
             David                                                         
             Wood/Watson/IBM@I                                             
             BMUS                                                       To 
                                       imperius-dev@incubator.apache.org   
             05/29/2009 10:14                                           cc 
             AM                        imperius-dev@incubator.apache.org   
                                                                   Subject 
                                       Re: svn commit: r779776 -           
             Please respond to         in /incubator/imperius/trunk/imperi 
             imperius-dev@incu         us-splcore/src/main/java/org/apache 
             bator.apache.org          /imperius/spl/parser/expressions/im 
                                       pl: LogicalAnd.java LogicalOr.java  
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




The original code did this

boolean right = ((Boolean) _rhsExp.evaluate()).booleanValue();

Always!  My change makes it so that it only does it if the left-hand side
evaluates to true (this is for the && case).  what you suggest would work
as well.

David Wood
Policy Technologies Group
IBM TJ Watson Research Center
dawood@us.ibm.com
914-784-5123 (office), 914-396-6515 (mobile)




From:
Xiping Wang/Watson/IBM@IBMUS
To:
imperius-dev@incubator.apache.org
Date:
05/29/2009 09:12 AM
Subject:
Re: svn commit: r779776 - in
/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl:

LogicalAnd.java LogicalOr.java



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


dawood@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");






Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message