You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2013/10/19 15:53:19 UTC
svn commit: r1533764 - in /poi/trunk/src/java/org/apache/poi:
hssf/record/ExtendedFormatRecord.java ss/usermodel/DateUtil.java
Author: yegor
Date: Sat Oct 19 13:53:19 2013
New Revision: 1533764
URL: http://svn.apache.org/r1533764
Log:
Patch 55611 - Performance improvement in DateUtil.isADateFormat(int, String)
Modified:
poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java?rev=1533764&r1=1533763&r2=1533764&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java Sat Oct 19 13:53:19 2013
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -1861,6 +1860,11 @@ public final class ExtendedFormatRecord
}
return false;
}
+
+ public int[] stateSummary() {
+ return new int[] { field_1_font_index, field_2_format_index, field_3_cell_options, field_4_alignment_options,
+ field_5_indention_options, field_6_border_options, field_7_palette_options, field_8_adtl_palette_options, field_9_fill_palette_options };
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java?rev=1533764&r1=1533763&r2=1533764&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java Sat Oct 19 13:53:19 2013
@@ -277,6 +277,14 @@ public class DateUtil {
}
+ // variables for performance optimization:
+ // avoid re-checking DataUtil.isADateFormat(int, String) if a given format
+ // string represents a date format if the same string is passed multiple times.
+ // see https://issues.apache.org/bugzilla/show_bug.cgi?id=55611
+ private static int lastFormatIndex = -1;
+ private static String lastFormatString = null;
+ private static boolean cached = false;
+
/**
* Given a format ID and its format String, will check to see if the
* format represents a date format or not.
@@ -290,14 +298,25 @@ public class DateUtil {
* @param formatString The format string, eg from FormatRecord.getFormatString
* @see #isInternalDateFormat(int)
*/
+
public static boolean isADateFormat(int formatIndex, String formatString) {
+
+ if (formatString != null && formatIndex == lastFormatIndex && formatString.equals(lastFormatString)) {
+ return cached;
+ }
// First up, is this an internal date format?
if(isInternalDateFormat(formatIndex)) {
+ lastFormatIndex = formatIndex;
+ lastFormatString = formatString;
+ cached = true;
return true;
}
// If we didn't get a real string, it can't be
if(formatString == null || formatString.length() == 0) {
+ lastFormatIndex = formatIndex;
+ lastFormatString = formatString;
+ cached = false;
return false;
}
@@ -349,6 +368,9 @@ public class DateUtil {
// short-circuit if it indicates elapsed time: [h], [m] or [s]
if(date_ptrn4.matcher(fs).matches()){
+ lastFormatIndex = formatIndex;
+ lastFormatString = formatString;
+ cached = true;
return true;
}
@@ -374,7 +396,12 @@ public class DateUtil {
// If we get here, check it's only made up, in any case, of:
// y m d h s - \ / , . : [ ]
// optionally followed by AM/PM
- return date_ptrn3b.matcher(fs).matches();
+
+ boolean result = date_ptrn3b.matcher(fs).matches();
+ lastFormatIndex = formatIndex;
+ lastFormatString = formatString;
+ cached = result;
+ return result;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org