bug 57840: add comments for explicit boxing performance optimization

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-15 01:42:11 +00:00
parent 72ef600ce0
commit 07c65c3fc4
2 changed files with 23 additions and 11 deletions

View File

@ -72,7 +72,8 @@ 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);
Integer colI = new Integer(cell.getColumnIndex()); // NOSONAR // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer colI = new Integer(cell.getColumnIndex()); // NOSONAR
_cells.put(colI, cell); _cells.put(colI, cell);
sheet.onReadCell(cell); sheet.onReadCell(cell);
} }
@ -198,6 +199,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
* @see Cell#CELL_TYPE_STRING * @see Cell#CELL_TYPE_STRING
*/ */
public XSSFCell createCell(int columnIndex, int type) { public XSSFCell createCell(int columnIndex, int type) {
// Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer colI = new Integer(columnIndex); // NOSONAR final Integer colI = new Integer(columnIndex); // NOSONAR
CTCell ctCell; CTCell ctCell;
XSSFCell prev = _cells.get(colI); XSSFCell prev = _cells.get(colI);
@ -238,7 +240,8 @@ 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");
Integer colI = new Integer(cellnum); // NOSONAR // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer colI = new Integer(cellnum); // NOSONAR
XSSFCell cell = _cells.get(colI); XSSFCell cell = _cells.get(colI);
if(policy == RETURN_NULL_AND_BLANK) { if(policy == RETURN_NULL_AND_BLANK) {
return cell; return cell;
@ -458,7 +461,8 @@ 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);
} }
Integer colI = new Integer(cell.getColumnIndex()); // NOSONAR // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer colI = new Integer(cell.getColumnIndex()); // NOSONAR
_cells.remove(colI); _cells.remove(colI);
} }

View File

@ -222,7 +222,8 @@ 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);
Integer rownumI = new Integer(r.getRowNum()); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR
_rows.put(rownumI, r); _rows.put(rownumI, r);
} }
} }
@ -693,6 +694,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public XSSFRow createRow(int rownum) { public XSSFRow createRow(int rownum) {
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(rownum); // NOSONAR final Integer rownumI = new Integer(rownum); // NOSONAR
CTRow ctRow; CTRow ctRow;
XSSFRow prev = _rows.get(rownumI); XSSFRow prev = _rows.get(rownumI);
@ -1379,7 +1381,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public XSSFRow getRow(int rownum) { public XSSFRow getRow(int rownum) {
Integer rownumI = new Integer(rownum); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(rownum); // NOSONAR
return _rows.get(rownumI); return _rows.get(rownumI);
} }
@ -1409,9 +1412,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
} }
} }
else { else {
Integer startI = new Integer(startRowNum); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
Integer endI = new Integer(endRowNum+1); // NOSONAR final Integer startI = new Integer(startRowNum); // NOSONAR
rows.addAll(_rows.subMap(startI, endI).values()); final Integer endI = new Integer(endRowNum+1); // NOSONAR
final Collection<XSSFRow> inclusive = _rows.subMap(startI, endI).values();
rows.addAll(inclusive);
} }
return rows; return rows;
} }
@ -1881,7 +1886,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
row.removeCell(cell); row.removeCell(cell);
} }
Integer rownumI = new Integer(row.getRowNum()); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(row.getRowNum()); // NOSONAR
int idx = _rows.headMap(rownumI).size(); int idx = _rows.headMap(rownumI).size();
_rows.remove(rownumI); _rows.remove(rownumI);
worksheet.getSheetData().removeRow(idx); worksheet.getSheetData().removeRow(idx);
@ -2899,7 +2905,8 @@ 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
Integer rownumI = new Integer(row.getRowNum()); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(row.getRowNum()); // NOSONAR
int idx = _rows.headMap(rownumI).size(); int idx = _rows.headMap(rownumI).size();
worksheet.getSheetData().removeRow(idx); worksheet.getSheetData().removeRow(idx);
@ -3019,7 +3026,8 @@ 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()) {
Integer rownumI = new Integer(r.getRowNum()); // NOSONAR // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR
map.put(rownumI, r); map.put(rownumI, r);
} }
_rows = map; _rows = map;