poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r579197 - /poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
Date Tue, 25 Sep 2007 11:09:09 GMT
Author: nick
Date: Tue Sep 25 04:08:57 2007
New Revision: 579197

URL: http://svn.apache.org/viewvc?rev=579197&view=rev
Log:
Improvement from Pavel - if we've already parsed a formula then evaluated it, don't re-do
the parsing the second time

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=579197&r1=579196&r2=579197&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Tue
Sep 25 04:08:57 2007
@@ -22,11 +22,14 @@
 
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
 import org.apache.poi.hssf.model.FormulaParser;
 import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.formula.AddPtg;
 import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.hssf.record.formula.AreaPtg;
@@ -294,25 +297,24 @@
     protected static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet
sheet, HSSFWorkbook workbook) {
         int srcRowNum = srcRow.getRowNum();
         short srcColNum = srcCell.getCellNum();
-        FormulaParser parser = new FormulaParser(srcCell.getCellFormula(), workbook.getWorkbook());
-        parser.parse();
-        Ptg[] ptgs = parser.getRPNPtg();
-        // -- parsing over --
         
-
+        FormulaRecordAggregate record = (FormulaRecordAggregate) srcCell.getCellValueRecord();
+        List ptgs = record.getFormulaRecord().getParsedExpression();
+        
         Stack stack = new Stack();
-        for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
-
+        for (int i = 0, iSize = ptgs.size(); i < iSize; i++) {
+            Ptg token = (Ptg) ptgs.get(i);
+            
             // since we dont know how to handle these yet :(
-            if (ptgs[i] instanceof ControlPtg) { continue; }
-            if (ptgs[i] instanceof MemErrPtg) { continue; }
-            if (ptgs[i] instanceof MissingArgPtg) { continue; }
-            if (ptgs[i] instanceof NamePtg) { continue; }
-            if (ptgs[i] instanceof NameXPtg) { continue; }
-            if (ptgs[i] instanceof UnknownPtg) { continue; }
+            if (token instanceof ControlPtg) { continue; }
+            if (token instanceof MemErrPtg) { continue; }
+            if (token instanceof MissingArgPtg) { continue; }
+            if (token instanceof NamePtg) { continue; }
+            if (token instanceof NameXPtg) { continue; }
+            if (token instanceof UnknownPtg) { continue; }
 
-            if (ptgs[i] instanceof OperationPtg) {
-                OperationPtg optg = (OperationPtg) ptgs[i];
+            if (token instanceof OperationPtg) {
+                OperationPtg optg = (OperationPtg) token;
 
                 // parens can be ignored since we have RPN tokens
                 if (optg instanceof ParenthesisPtg) { continue; }
@@ -332,16 +334,16 @@
                 Eval opresult = operation.evaluate(ops, srcRowNum, srcColNum);
                 stack.push(opresult);
             }
-            else if (ptgs[i] instanceof ReferencePtg) {
-                ReferencePtg ptg = (ReferencePtg) ptgs[i];
+            else if (token instanceof ReferencePtg) {
+                ReferencePtg ptg = (ReferencePtg) token;
                 short colnum = ptg.getColumn();
                 short rownum = ptg.getRow();
                 HSSFRow row = sheet.getRow(rownum);
                 HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
                 pushRef2DEval(ptg, stack, cell, row, sheet, workbook);
             }
-            else if (ptgs[i] instanceof Ref3DPtg) {
-                Ref3DPtg ptg = (Ref3DPtg) ptgs[i];
+            else if (token instanceof Ref3DPtg) {
+                Ref3DPtg ptg = (Ref3DPtg) token;
                 short colnum = ptg.getColumn();
                 short rownum = ptg.getRow();
                 Workbook wb = workbook.getWorkbook();
@@ -350,8 +352,8 @@
                 HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
                 pushRef3DEval(ptg, stack, cell, row, xsheet, workbook);
             }
-            else if (ptgs[i] instanceof AreaPtg) {
-                AreaPtg ap = (AreaPtg) ptgs[i];
+            else if (token instanceof AreaPtg) {
+                AreaPtg ap = (AreaPtg) token;
                 short row0 = ap.getFirstRow();
                 short col0 = ap.getFirstColumn();
                 short row1 = ap.getLastRow();
@@ -367,8 +369,8 @@
                 AreaEval ae = new Area2DEval(ap, values);
                 stack.push(ae);
             }
-            else if (ptgs[i] instanceof Area3DPtg) {
-                Area3DPtg a3dp = (Area3DPtg) ptgs[i];
+            else if (token instanceof Area3DPtg) {
+                Area3DPtg a3dp = (Area3DPtg) token;
                 short row0 = a3dp.getFirstRow();
                 short col0 = a3dp.getFirstColumn();
                 short row1 = a3dp.getLastRow();
@@ -387,7 +389,7 @@
                 stack.push(ae);
             }
             else {
-                Eval ptgEval = getEvalForPtg(ptgs[i]);
+                Eval ptgEval = getEvalForPtg(token);
                 stack.push(ptgEval);
             }
         }
@@ -698,3 +700,4 @@
     }
 
 }
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message