diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 76d616f47..5a90ab94e 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Tweak the logic for sizing the HSSFCells array on a HSSFRow to reduce memory over allocation in many use cases 49765 - Support for adding a picture to a XSSFRun Rename/Move xssf.model.Table to xssf.usermodel.XSSFTable as it now has usermodel-like features 51061 - Correct target URI for new XSSF Tables diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java index 3d1c73497..4d8102867 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -41,7 +41,7 @@ public final class HSSFRow implements Row { public final static int INITIAL_CAPACITY = 5; private int rowNum; - private HSSFCell[] cells=new HSSFCell[INITIAL_CAPACITY]; + private HSSFCell[] cells; /** * reference to low level representation @@ -84,6 +84,12 @@ public final class HSSFRow implements Row { this.sheet = sheet; row = record; setRowNum(record.getRowNumber()); + + // Size the initial cell list such that a read only case won't waste + // lots of memory, and a create/read followed by adding new cells can + // add a bit without needing a resize + cells = new HSSFCell[record.getLastCol()+INITIAL_CAPACITY]; + // Don't trust colIx boundaries as read by other apps // set the RowRecord empty for the moment record.setEmpty(); @@ -300,9 +306,10 @@ public final class HSSFRow implements Row { // re-allocate cells array as required. if(column>=cells.length) { HSSFCell[] oldCells=cells; - int newSize=oldCells.length*2; + // New size based on the same logic as ArrayList + int newSize=oldCells.length*3/2+1; if(newSize