]> source.dussan.org Git - poi.git/commitdiff
bug 57840: add comments for explicit boxing performance optimization
authorJaven O'Neal <onealj@apache.org>
Wed, 15 Jun 2016 01:42:11 +0000 (01:42 +0000)
committerJaven O'Neal <onealj@apache.org>
Wed, 15 Jun 2016 01:42:11 +0000 (01:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748479 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index a22d37a77675ef3a758e6d43cbfc5c027135cfb1..4b73e36ca588a43b4a7f5096ac31a68b79f6a2f3 100644 (file)
@@ -72,7 +72,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
         _cells = new TreeMap<Integer, XSSFCell>();
         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<XSSFRow> {
      * @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<XSSFRow> {
     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<XSSFRow> {
         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);
     }
 
index 8bf65f18f25077bb2e7c82e5668c8ff8f92b279b..13f6b09165e854514cdc3a1e7ba436e59d76c259 100644 (file)
@@ -222,7 +222,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         arrayFormulas = new ArrayList<CellRangeAddress>();
         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<XSSFRow> 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<Integer, XSSFRow> map = new TreeMap<Integer, XSSFRow>();
         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;