]> source.dussan.org Git - poi.git/commitdiff
[bug-66607] perf issue processing array formulas
authorPJ Fanning <fanningpj@apache.org>
Fri, 19 May 2023 13:09:15 +0000 (13:09 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 19 May 2023 13:09:15 +0000 (13:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1909934 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index 4605ee04e04c47e8fd164b0d7b0217e22e7116e2..289b08dda69c388ebcd622046df476e90782f6ea 100644 (file)
@@ -113,7 +113,8 @@ public class XSSFImportFromXML {
                 String textContent = result.getTextContent();
                 LOG.atDebug().log("Extracting with xpath {} : value is '{}'", xpathString, textContent);
                 XSSFCell cell = singleXmlCell.getReferencedCell();
-                LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", textContent, box(cell.getColumnIndex()),box(cell.getRowIndex()),cell.getSheet().getSheetName());
+                LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", textContent,
+                        box(cell.getColumnIndex()), box(cell.getRowIndex()), cell.getSheet().getSheetName());
                 setCellValue(textContent, cell, xmlDataType);
             }
         }
@@ -158,7 +159,8 @@ public class XSSFImportFromXML {
                     if (cell == null) {
                         cell = row.createCell(columnId);
                     }
-                    LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", value, box(cell.getColumnIndex()),box(cell.getRowIndex()),table.getXSSFSheet().getSheetName());
+                    LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", value,
+                            box(cell.getColumnIndex()), box(cell.getRowIndex()), table.getXSSFSheet().getSheetName());
                     setCellValue(value, cell, xmlColumnPr.getXmlDataType());
                 }
             }
index df74b227b478819f4aff9497c9e26c1c4a93757e..3f80c18e817778aaecd40ebd4bc006a067e86766 100644 (file)
@@ -81,7 +81,7 @@ public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
     public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
         final XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
         final int sheetIndex = _uBook.getSheetIndex(cell.getSheet());
-        final int rowIndex = cell.getRowIndex();
-        return FormulaParser.parse(cell.getCellFormula(this), this, FormulaType.CELL, sheetIndex, rowIndex);
+        return FormulaParser.parse(cell.getCellFormula(this), this,
+                FormulaType.CELL, sheetIndex, cell.getRowIndex());
     }
 }
index 0ffb4aed2360626a323f8b9a59caa07c79b1aadd..70ed47e89e8b71c51fee9cd90827c44c689e69fd 100644 (file)
@@ -4171,8 +4171,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
     }
 
     /* package */ boolean isCellInArrayFormulaContext(XSSFCell cell) {
+        final int rowIndex = cell.getRowIndex();
+        final int columnIndex = cell.getColumnIndex();
         for (CellRangeAddress range : arrayFormulas) {
-            if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) {
+            if (range.isInRange(rowIndex, columnIndex)) {
                 return true;
             }
         }
@@ -4180,8 +4182,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
     }
 
     /* package */ XSSFCell getFirstCellInArrayFormula(XSSFCell cell) {
+        final int rowIndex = cell.getRowIndex();
+        final int columnIndex = cell.getColumnIndex();
         for (CellRangeAddress range : arrayFormulas) {
-            if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) {
+            if (range.isInRange(rowIndex, columnIndex)) {
                 return getRow(range.getFirstRow()).getCell(range.getFirstColumn());
             }
         }
@@ -4868,18 +4872,19 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
      * @param cell The cell that is removed
      * @param evalWb BaseXSSFEvaluationWorkbook in use, if one exists
      */
-    protected void onDeleteFormula(XSSFCell cell, BaseXSSFEvaluationWorkbook evalWb){
-
+    protected void onDeleteFormula(final XSSFCell cell, final BaseXSSFEvaluationWorkbook evalWb) {
+        final int rowIndex = cell.getRowIndex();
+        final int columnIndex = cell.getColumnIndex();
         CTCellFormula f = cell.getCTCell().getF();
         if (f != null && f.getT() == STCellFormulaType.SHARED && f.isSetRef() && f.getStringValue() != null) {
 
             CellRangeAddress ref = CellRangeAddress.valueOf(f.getRef());
             if(ref.getNumberOfCells() > 1){
                 DONE:
-                for(int i = cell.getRowIndex(); i <= ref.getLastRow(); i++){
+                for(int i = rowIndex; i <= ref.getLastRow(); i++){
                     XSSFRow row = getRow(i);
                     if(row != null) {
-                        for(int j = cell.getColumnIndex(); j <= ref.getLastColumn(); j++){
+                        for(int j = columnIndex; j <= ref.getLastColumn(); j++){
                             XSSFCell nextCell = row.getCell(j);
                             if(nextCell != null && nextCell != cell && nextCell.getCellType() == CellType.FORMULA) {
                                 CTCellFormula nextF = nextCell.getCTCell().getF();