From e1000f257e2e610de7235d9cff14ddee59f24976 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 4 Jun 2014 15:58:14 +0000 Subject: [PATCH] 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 --- .../poi/xssf/usermodel/helpers/ColumnHelper.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) { -- 2.39.5