From: Nick Burch Date: Wed, 4 Jun 2014 15:58:14 +0000 (+0000) Subject: When finding the CTCol object for a XSSF Sheet column, as we often have to traverse... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e1000f257e2e610de7235d9cff14ddee59f24976;p=poi.git 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 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java index 767fb6e0b6..41beb6f259 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java @@ -199,8 +199,15 @@ public class ColumnHelper { */ public CTCol getColumn1Based(long index1, boolean splitColumns) { 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 (splitColumns) { if (colArray.getMin() < index1) {