From: PJ Fanning Date: Fri, 19 May 2023 13:09:15 +0000 (+0000) Subject: [bug-66607] perf issue processing array formulas X-Git-Tag: REL_5_2_4~157 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=60d5336f7c62eb1a4320ef01b0d9337d95d2db01;p=poi.git [bug-66607] perf issue processing array formulas git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1909934 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java index 4605ee04e0..289b08dda6 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java @@ -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()); } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java index df74b227b4..3f80c18e81 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java @@ -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()); } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 0ffb4aed23..70ed47e89e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -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();