When finding the CTCol object for a XSSF Sheet column, as we often have to traverse most of the list, and we are mostly reading not changing, switch to fetching all the objects as an array in one go, rather than fetching one at a time, which is hopefully faster. Aims to help bug #56556

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1600319 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-06-04 15:58:14 +00:00
parent 1d52c63292
commit e1000f257e

View File

@ -199,8 +199,15 @@ public class ColumnHelper {
*/ */
public CTCol getColumn1Based(long index1, boolean splitColumns) { public CTCol getColumn1Based(long index1, boolean splitColumns) {
CTCols colsArray = worksheet.getColsArray(0); CTCols colsArray = worksheet.getColsArray(0);
for (int i = 0; i < colsArray.sizeOfColArray(); i++) {
CTCol colArray = colsArray.getColArray(i); // Fetching the array is quicker than working on the new style
// list, assuming we need to read many of them (which we often do),
// and assuming we're not making many changes (which we're not)
@SuppressWarnings("deprecation")
CTCol[] cols = colsArray.getColArray();
for (int i = 0; i < cols.length; i++) {
CTCol colArray = cols[i];
if (colArray.getMin() <= index1 && colArray.getMax() >= index1) { if (colArray.getMin() <= index1 && colArray.getMax() >= index1) {
if (splitColumns) { if (splitColumns) {
if (colArray.getMin() < index1) { if (colArray.getMin() < index1) {