From 07c65c3fc497036a98da32c995dfc03bc477e1de Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 15 Jun 2016 01:42:11 +0000 Subject: [PATCH] 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 --- .../apache/poi/xssf/usermodel/XSSFRow.java | 10 +++++--- .../apache/poi/xssf/usermodel/XSSFSheet.java | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index a22d37a776..4b73e36ca5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -72,7 +72,8 @@ public class XSSFRow implements Row, Comparable { _cells = new TreeMap(); for (CTCell c : row.getCArray()) { 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); sheet.onReadCell(cell); } @@ -198,6 +199,7 @@ public class XSSFRow implements Row, Comparable { * @see Cell#CELL_TYPE_STRING */ 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 CTCell ctCell; XSSFCell prev = _cells.get(colI); @@ -238,7 +240,8 @@ public class XSSFRow implements Row, Comparable { public XSSFCell getCell(int cellnum, MissingCellPolicy policy) { 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); if(policy == RETURN_NULL_AND_BLANK) { return cell; @@ -458,7 +461,8 @@ public class XSSFRow implements Row, Comparable { if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) { _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); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 8bf65f18f2..13f6b09165 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -222,7 +222,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { arrayFormulas = new ArrayList(); for (CTRow row : worksheetParam.getSheetData().getRowArray()) { 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); } } @@ -693,6 +694,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ @Override 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 CTRow ctRow; XSSFRow prev = _rows.get(rownumI); @@ -1379,7 +1381,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ @Override 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); } @@ -1409,9 +1412,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } } else { - Integer startI = new Integer(startRowNum); // NOSONAR - Integer endI = new Integer(endRowNum+1); // NOSONAR - rows.addAll(_rows.subMap(startI, endI).values()); + // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + final Integer startI = new Integer(startRowNum); // NOSONAR + final Integer endI = new Integer(endRowNum+1); // NOSONAR + final Collection inclusive = _rows.subMap(startI, endI).values(); + rows.addAll(inclusive); } return rows; } @@ -1881,7 +1886,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { 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(); _rows.remove(rownumI); 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 if (shouldRemoveRow(startRow, endRow, n, rownum)) { // 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(); worksheet.getSheetData().removeRow(idx); @@ -3019,7 +3026,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { //rebuild the _rows map SortedMap map = new TreeMap(); 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); } _rows = map; -- 2.39.5