ASF Bugzilla – Attachment 33940 Details for
Bug 57840
[PATCH] Support for structured references with Excel tables.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
cache XSSFCellEvaluator instances and look up by hash key - much faster
patch-57840-cache-eval-cells.txt (text/plain), 3.74 KB, created by
Greg Woolsey
on 2016-06-11 00:52:03 UTC
(
hide
)
Description:
cache XSSFCellEvaluator instances and look up by hash key - much faster
Filename:
MIME Type:
Creator:
Greg Woolsey
Created:
2016-06-11 00:52:03 UTC
Size:
3.74 KB
patch
obsolete
>Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java (revision 1747768) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java (working copy) >@@ -17,8 +17,13 @@ > > package org.apache.poi.xssf.usermodel; > >+import java.util.HashMap; >+import java.util.Map; >+ > import org.apache.poi.ss.formula.EvaluationCell; > import org.apache.poi.ss.formula.EvaluationSheet; >+import org.apache.poi.ss.usermodel.Cell; >+import org.apache.poi.ss.usermodel.Row; > > /** > * XSSF wrapper for a sheet under evaluation >@@ -26,6 +31,7 @@ > final class XSSFEvaluationSheet implements EvaluationSheet { > > private final XSSFSheet _xs; >+ private Map<CellKey, EvaluationCell> _cellCache; > > public XSSFEvaluationSheet(XSSFSheet sheet) { > _xs = sheet; >@@ -35,14 +41,40 @@ > return _xs; > } > public EvaluationCell getCell(int rowIndex, int columnIndex) { >- XSSFRow row = _xs.getRow(rowIndex); >- if (row == null) { >- return null; >- } >- XSSFCell cell = row.getCell(columnIndex); >- if (cell == null) { >- return null; >- } >- return new XSSFEvaluationCell(cell, this); >+ if (_cellCache == null) { >+ _cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum()*3); >+ for (Row row : _xs) { >+ for (Cell cell : row) { >+ // cast is safe, the iterator is just defined using the interface >+ _cellCache.put(new CellKey(row.getRowNum(), cell.getColumnIndex()), new XSSFEvaluationCell((XSSFCell) cell, this)); >+ } >+ } >+ } >+ >+ return _cellCache.get(new CellKey(rowIndex, columnIndex)); >+ > } >+ >+ private static class CellKey { >+ private final int _row; >+ private final int _col; >+ private final int _hash; >+ >+ protected CellKey(int row, int col) { >+ _row = row; >+ _col = col; >+ _hash = (17 * 37 + row) *37 + col; >+ } >+ >+ public int hashCode() { >+ return _hash; >+ } >+ >+ public boolean equals(Object obj) { >+ if (obj == null) return false; >+ // assumes other object is one of us >+ final CellKey oKey = (CellKey) obj; >+ return _row == oKey._row && _col == oKey._col; >+ } >+ } > } >Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (revision 1747768) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (working copy) >@@ -27,6 +27,8 @@ > * Internal POI use only > */ > public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook { >+ private XSSFEvaluationSheet[] _sheetCache; >+ > public static XSSFEvaluationWorkbook create(XSSFWorkbook book) { > if (book == null) { > return null; >@@ -46,7 +48,17 @@ > > @Override > public EvaluationSheet getSheet(int sheetIndex) { >- return new XSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex)); >+ if (_sheetCache == null) { >+ _sheetCache = new XSSFEvaluationSheet[_uBook.getNumberOfSheets()]; >+ for (int i=0; i < _uBook.getNumberOfSheets(); i++) { >+ _sheetCache[i] = new XSSFEvaluationSheet(_uBook.getSheetAt(i)); >+ } >+ } >+ if (sheetIndex < 0 || sheetIndex >= _sheetCache.length) { >+ // do this to reuse the out-of-bounds logic and message from XSSFWorkbook >+ _uBook.getSheetAt(sheetIndex); >+ } >+ return _sheetCache[sheetIndex]; > } > > @Override
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57840
:
32671
|
33927
|
33932
|
33937
|
33938
|
33939
| 33940 |
33941
|
33942