bug 57840: avoid auto-boxing ints for row/column TreeTable lookups (4% evaluation speedup at the cost of additional Integer objects); patch from Greg Woolsey

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-11 01:48:37 +00:00
parent 9ca89c2278
commit 6d03eafcfe
2 changed files with 15 additions and 15 deletions

View File

@ -72,7 +72,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
_cells = new TreeMap<Integer, XSSFCell>(); _cells = new TreeMap<Integer, XSSFCell>();
for (CTCell c : row.getCArray()) { for (CTCell c : row.getCArray()) {
XSSFCell cell = new XSSFCell(this, c); XSSFCell cell = new XSSFCell(this, c);
_cells.put(cell.getColumnIndex(), cell); _cells.put(new Integer(cell.getColumnIndex()), cell);
sheet.onReadCell(cell); sheet.onReadCell(cell);
} }
} }
@ -198,7 +198,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
public XSSFCell createCell(int columnIndex, int type) { public XSSFCell createCell(int columnIndex, int type) {
CTCell ctCell; CTCell ctCell;
XSSFCell prev = _cells.get(columnIndex); XSSFCell prev = _cells.get(new Integer(columnIndex));
if(prev != null){ if(prev != null){
ctCell = prev.getCTCell(); ctCell = prev.getCTCell();
ctCell.set(CTCell.Factory.newInstance()); ctCell.set(CTCell.Factory.newInstance());
@ -210,7 +210,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
if (type != Cell.CELL_TYPE_BLANK) { if (type != Cell.CELL_TYPE_BLANK) {
xcell.setCellType(type); xcell.setCellType(type);
} }
_cells.put(columnIndex, xcell); _cells.put(new Integer(columnIndex), xcell);
return xcell; return xcell;
} }
@ -236,7 +236,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
public XSSFCell getCell(int cellnum, MissingCellPolicy policy) { public XSSFCell getCell(int cellnum, MissingCellPolicy policy) {
if(cellnum < 0) throw new IllegalArgumentException("Cell index must be >= 0"); if(cellnum < 0) throw new IllegalArgumentException("Cell index must be >= 0");
XSSFCell cell = _cells.get(cellnum); XSSFCell cell = _cells.get(new Integer(cellnum));
if(policy == RETURN_NULL_AND_BLANK) { if(policy == RETURN_NULL_AND_BLANK) {
return cell; return cell;
} }
@ -455,7 +455,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) { if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
_sheet.getWorkbook().onDeleteFormula(xcell); _sheet.getWorkbook().onDeleteFormula(xcell);
} }
_cells.remove(cell.getColumnIndex()); _cells.remove(new Integer(cell.getColumnIndex()));
} }
/** /**

View File

@ -222,7 +222,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
arrayFormulas = new ArrayList<CellRangeAddress>(); arrayFormulas = new ArrayList<CellRangeAddress>();
for (CTRow row : worksheetParam.getSheetData().getRowArray()) { for (CTRow row : worksheetParam.getSheetData().getRowArray()) {
XSSFRow r = new XSSFRow(row, this); XSSFRow r = new XSSFRow(row, this);
_rows.put(r.getRowNum(), r); _rows.put(new Integer(r.getRowNum()), r);
} }
} }
@ -693,7 +693,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
@Override @Override
public XSSFRow createRow(int rownum) { public XSSFRow createRow(int rownum) {
CTRow ctRow; CTRow ctRow;
XSSFRow prev = _rows.get(rownum); XSSFRow prev = _rows.get(new Integer(rownum));
if(prev != null){ if(prev != null){
// the Cells in an existing row are invalidated on-purpose, in order to clean up correctly, we // the Cells in an existing row are invalidated on-purpose, in order to clean up correctly, we
// need to call the remove, so things like ArrayFormulas and CalculationChain updates are done // need to call the remove, so things like ArrayFormulas and CalculationChain updates are done
@ -713,13 +713,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
} else { } else {
// get number of rows where row index < rownum // get number of rows where row index < rownum
// --> this tells us where our row should go // --> this tells us where our row should go
int idx = _rows.headMap(rownum).size(); int idx = _rows.headMap(new Integer(rownum)).size();
ctRow = worksheet.getSheetData().insertNewRow(idx); ctRow = worksheet.getSheetData().insertNewRow(idx);
} }
} }
XSSFRow r = new XSSFRow(ctRow, this); XSSFRow r = new XSSFRow(ctRow, this);
r.setRowNum(rownum); r.setRowNum(rownum);
_rows.put(rownum, r); _rows.put(new Integer(rownum), r);
return r; return r;
} }
@ -1377,7 +1377,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public XSSFRow getRow(int rownum) { public XSSFRow getRow(int rownum) {
return _rows.get(rownum); return _rows.get(new Integer(rownum));
} }
/** /**
@ -1406,7 +1406,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
} }
} }
else { else {
rows.addAll(_rows.subMap(startRowNum, endRowNum+1).values()); rows.addAll(_rows.subMap(new Integer(startRowNum), new Integer(endRowNum+1)).values());
} }
return rows; return rows;
} }
@ -1876,8 +1876,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
row.removeCell(cell); row.removeCell(cell);
} }
int idx = _rows.headMap(row.getRowNum()).size(); int idx = _rows.headMap(new Integer(row.getRowNum())).size();
_rows.remove(row.getRowNum()); _rows.remove(new Integer(row.getRowNum()));
worksheet.getSheetData().removeRow(idx); worksheet.getSheetData().removeRow(idx);
// also remove any comment located in that row // also remove any comment located in that row
@ -2893,7 +2893,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
// check if we should remove this row as it will be overwritten by the data later // check if we should remove this row as it will be overwritten by the data later
if (shouldRemoveRow(startRow, endRow, n, rownum)) { if (shouldRemoveRow(startRow, endRow, n, rownum)) {
// remove row from worksheet.getSheetData row array // remove row from worksheet.getSheetData row array
int idx = _rows.headMap(row.getRowNum()).size(); int idx = _rows.headMap(new Integer(row.getRowNum())).size();
worksheet.getSheetData().removeRow(idx); worksheet.getSheetData().removeRow(idx);
// remove row from _rows // remove row from _rows
@ -3012,7 +3012,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
//rebuild the _rows map //rebuild the _rows map
SortedMap<Integer, XSSFRow> map = new TreeMap<Integer, XSSFRow>(); SortedMap<Integer, XSSFRow> map = new TreeMap<Integer, XSSFRow>();
for(XSSFRow r : _rows.values()) { for(XSSFRow r : _rows.values()) {
map.put(r.getRowNum(), r); map.put(new Integer(r.getRowNum()), r);
} }
_rows = map; _rows = map;
} }