diff -rupN -x '.*' poi-3.9/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java poi-3.9-patch/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java --- poi-3.9/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java 2012-11-25 13:27:35.000000000 +0100 +++ poi-3.9-patch/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java 2013-10-19 19:14:48.000000000 +0200 @@ -18,9 +18,13 @@ package org.apache.poi.hssf.usermodel; +import java.util.Arrays; +import java.util.List; + import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.FontRecord; +import org.apache.poi.hssf.record.FormatRecord; import org.apache.poi.hssf.record.StyleRecord; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; @@ -106,8 +110,28 @@ public final class HSSFCellStyle impleme * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * @return the format string or "General" if not found */ + + private static short lastDateFormat = Short.MIN_VALUE; + private static List lastFormats = null; + private static String getDataFormatStringCache = null; + + private static final Object cacheLock = new Object(); + public String getDataFormatString() { - return getDataFormatString(_workbook); + synchronized (cacheLock) { + if (getDataFormatStringCache != null) { + if (lastDateFormat == getDataFormat() && _workbook.getFormats().equals(lastFormats)) { + return getDataFormatStringCache; + } + } + + lastFormats = _workbook.getFormats(); + lastDateFormat = getDataFormat(); + + getDataFormatStringCache = getDataFormatString(_workbook); + + return getDataFormatStringCache; + } } /** * Get the contents of the format string, by looking up @@ -828,6 +852,13 @@ public final class HSSFCellStyle impleme // Handle matching things if we cross workbooks if(_workbook != source._workbook) { + + synchronized (cacheLock) { + lastDateFormat = Short.MIN_VALUE; + lastFormats = null; + getDataFormatStringCache = null; + } + // Then we need to clone the format string, // and update the format record for this short fmt = (short)_workbook.createFormat(source.getDataFormatString() ); @@ -874,4 +905,5 @@ public final class HSSFCellStyle impleme } return false; } + }