From 93ed98da08a6a578ddba7d17e81aafaf67d04506 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 19 Jun 2016 22:24:17 +0000 Subject: [PATCH] bug 56958: slightly improve performance when checking array formulas git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749219 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/usermodel/HSSFSheet.java | 8 +++++--- .../org/apache/poi/xssf/usermodel/XSSFSheet.java | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 9f858b7794..c7788d09bb 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -735,15 +735,17 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } private void validateArrayFormulas(CellRangeAddress region) { + // FIXME: this may be faster if it looped over array formulas directly rather than looping over each cell in + // the region and searching if that cell belongs to an array formula int firstRow = region.getFirstRow(); int firstColumn = region.getFirstColumn(); int lastRow = region.getLastRow(); int lastColumn = region.getLastColumn(); for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) { + HSSFRow row = getRow(rowIn); + if (row == null) continue; + for (int colIn = firstColumn; colIn <= lastColumn; colIn++) { - HSSFRow row = getRow(rowIn); - if (row == null) continue; - HSSFCell cell = row.getCell(colIn); if (cell == null) continue; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 5df45e9078..edc8000a4e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -379,21 +379,23 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * @param region * @throws IllegalStateException if candidate region intersects an existing array formula in this sheet */ - private void validateArrayFormulas(CellRangeAddress region){ + private void validateArrayFormulas(CellRangeAddress region) { + // FIXME: this may be faster if it looped over array formulas directly rather than looping over each cell in + // the region and searching if that cell belongs to an array formula int firstRow = region.getFirstRow(); int firstColumn = region.getFirstColumn(); int lastRow = region.getLastRow(); int lastColumn = region.getLastColumn(); // for each cell in sheet, if cell belongs to an array formula, check if merged region intersects array formula cells for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) { + XSSFRow row = getRow(rowIn); + if (row == null) continue; + for (int colIn = firstColumn; colIn <= lastColumn; colIn++) { - XSSFRow row = getRow(rowIn); - if (row == null) continue; - XSSFCell cell = row.getCell(colIn); - if(cell == null) continue; + if (cell == null) continue; - if(cell.isPartOfArrayFormulaGroup()){ + if (cell.isPartOfArrayFormulaGroup()) { CellRangeAddress arrayRange = cell.getArrayFormulaRange(); if (arrayRange.getNumberOfCells() > 1 && region.intersects(arrayRange)) { String msg = "The range " + region.formatAsString() + " intersects with a multi-cell array formula. " + -- 2.39.5