summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2020-12-10 18:18:51 +0000
committerPJ Fanning <fanningpj@apache.org>2020-12-10 18:18:51 +0000
commitc0ecc83ee4e52e8feffa4737e276420ac4451fca (patch)
tree5b3a58e6fea2853cc702a95cef9557cbfd75e3ad /src
parentda146d33998d1f4e0e8c78910e1c9bb3cfef8678 (diff)
downloadpoi-c0ecc83ee4e52e8feffa4737e276420ac4451fca.tar.gz
poi-c0ecc83ee4e52e8feffa4737e276420ac4451fca.zip
[github-206] Improve perfomance of SXSSF cell evaluation. Thanks to This closes #206
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884288 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java35
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java20
2 files changed, 29 insertions, 26 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
index 9f0379493b..8d6e903d9d 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
@@ -49,6 +49,7 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
// use Boolean to have a tri-state for on/off/undefined
private Boolean _hidden = UNDEFINED;
private Boolean _collapsed = UNDEFINED;
+ private int _rowNum;
public SXSSFRow(SXSSFSheet sheet)
{
@@ -59,6 +60,7 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
{
return new CellIterator();
}
+
public boolean hasCustomHeight()
{
return _height!=-1;
@@ -195,7 +197,8 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
@Override
public void setRowNum(int rowNum)
{
- _sheet.changeRowNum(this,rowNum);
+ this._rowNum = rowNum;
+ _sheet.changeRowNum(this, rowNum);
}
/**
@@ -206,7 +209,7 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
@Override
public int getRowNum()
{
- return _sheet.getRowNum(this);
+ return _rowNum;
}
/**
@@ -393,15 +396,15 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
*/
@Override
public CellStyle getRowStyle() {
- if(!isFormatted()) {
- return null;
- }
+ if(!isFormatted()) {
+ return null;
+ }
- return getSheet().getWorkbook().getCellStyleAt(_style);
+ return getSheet().getWorkbook().getCellStyleAt(_style);
}
@Internal
- /*package*/ int getRowStyleIndex() {
+ /*package*/ int getRowStyleIndex() {
return _style;
}
@@ -411,11 +414,11 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
*/
@Override
public void setRowStyle(CellStyle style) {
- if(style == null) {
- _style = -1;
- } else {
- _style = style.getIndex();
- }
+ if(style == null) {
+ _style = -1;
+ } else {
+ _style = style.getIndex();
+ }
}
/**
@@ -437,8 +440,13 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
{
return _sheet;
}
+
//end of interface implementation
+ void setRowNumWithoutUpdatingSheet(int rowNum)
+ {
+ this._rowNum = rowNum;
+ }
/**
* Create an iterator over the cells from [0, getLastCellNum()).
@@ -543,7 +551,7 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
SXSSFRow other = (SXSSFRow) obj;
return (this.getRowNum() == other.getRowNum()) &&
- (this.getSheet() == other.getSheet());
+ (this.getSheet() == other.getSheet());
}
@Override
@@ -563,4 +571,3 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
}
}
-
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
index 9c67e9f49e..04e0c0e735 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
@@ -146,6 +146,7 @@ public class SXSSFSheet implements Sheet
}
SXSSFRow newRow = new SXSSFRow(this);
+ newRow.setRowNumWithoutUpdatingSheet(rownum);
_rows.put(rownum, newRow);
allFlushed = false;
if(_randomAccessWindowSize >= 0 && _rows.size() > _randomAccessWindowSize) {
@@ -1293,8 +1294,8 @@ public class SXSSFSheet implements Sheet
*
* <p>
* groupRows requires all rows in the group to be in the current window.
- * This is not always practical. Instead use setRowOutlineLevel to
- * explicitly set the group level. Level 1 is the top level group,
+ * This is not always practical. Instead use setRowOutlineLevel to
+ * explicitly set the group level. Level 1 is the top level group,
* followed by 2, etc. It is up to the user to ensure that level 2
* groups are correctly nested under level 1, etc.
* </p>
@@ -1588,7 +1589,7 @@ public class SXSSFSheet implements Sheet
// to recalculate the best-fit width for the flushed rows. This is an
// inherent limitation of SXSSF. If having correct auto-sizing is
// critical, the flushed rows would need to be re-read by the read-only
- // XSSF eventmodel (SAX) or the memory-heavy XSSF usermodel (DOM).
+ // XSSF eventmodel (SAX) or the memory-heavy XSSF usermodel (DOM).
final int flushedWidth;
try {
// get the best fit width of rows already flushed to disk
@@ -1885,22 +1886,17 @@ public class SXSSFSheet implements Sheet
lastFlushedRowNumber = rowIndex;
}
}
+
public void changeRowNum(SXSSFRow row, int newRowNum)
{
-
removeRow(row);
- _rows.put(newRowNum,row);
+ row.setRowNumWithoutUpdatingSheet(newRowNum);
+ _rows.put(newRowNum, row);
}
public int getRowNum(SXSSFRow row)
{
- for (Map.Entry<Integer, SXSSFRow> entry : _rows.entrySet()) {
- if (entry.getValue() == row) {
- return entry.getKey().intValue();
- }
- }
-
- return -1;
+ return row.getRowNum();
}
/**