summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-04-19 22:26:46 +0000
committerNick Burch <nick@apache.org>2011-04-19 22:26:46 +0000
commitfa87b4277465227c029c919a2d6d7d3e1bf9229b (patch)
treec66299ac4b8dea26f37563e35ed801f69db499e5
parent020121825c6b329282d9bad147a40bd15cf85e3b (diff)
downloadpoi-fa87b4277465227c029c919a2d6d7d3e1bf9229b.tar.gz
poi-fa87b4277465227c029c919a2d6d7d3e1bf9229b.zip
Following discussions on the dev list today, tweak the logic for sizing the HSSFCells array on a HSSFRow to reduce memory over allocation in many use cases (now cribbed from the size of the row, and uses the ArrayList growth metric)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1095229 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFRow.java13
2 files changed, 11 insertions, 3 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 76d616f47f..5a90ab94e0 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta3" date="2011-??-??">
+ <action dev="poi-developers" type="fix">Tweak the logic for sizing the HSSFCells array on a HSSFRow to reduce memory over allocation in many use cases</action>
<action dev="poi-developers" type="add">49765 - Support for adding a picture to a XSSFRun</action>
<action dev="poi-developers" type="fix">Rename/Move xssf.model.Table to xssf.usermodel.XSSFTable as it now has usermodel-like features</action>
<action dev="poi-developers" type="fix">51061 - Correct target URI for new XSSF Tables</action>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
index 3d1c73497b..4d8102867f 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<column+1) {
- newSize=column+1;
+ newSize=column+INITIAL_CAPACITY;
}
cells=new HSSFCell[newSize];
System.arraycopy(oldCells,0,cells,0,oldCells.length);