Return-Path: X-Original-To: apmail-poi-dev-archive@www.apache.org Delivered-To: apmail-poi-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6C62210075 for ; Sat, 19 Oct 2013 15:28:27 +0000 (UTC) Received: (qmail 63096 invoked by uid 500); 19 Oct 2013 15:28:26 -0000 Delivered-To: apmail-poi-dev-archive@poi.apache.org Received: (qmail 63042 invoked by uid 500); 19 Oct 2013 15:28:26 -0000 Mailing-List: contact dev-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Developers List" Delivered-To: mailing list dev@poi.apache.org Received: (qmail 63034 invoked by uid 99); 19 Oct 2013 15:28:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Oct 2013 15:28:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.115] (HELO eir.zones.apache.org) (140.211.11.115) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Oct 2013 15:28:23 +0000 Received: by eir.zones.apache.org (Postfix, from userid 80) id 3094DAC85; Sat, 19 Oct 2013 15:28:02 +0000 (UTC) From: bugzilla@apache.org To: dev@poi.apache.org Subject: [Bug 55611] Performance improvement (~7% up to ~27%) by adding a cache to DateUtil.isADateFormat(int, String) Date: Sat, 19 Oct 2013 15:28:02 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: POI X-Bugzilla-Component: HSSF X-Bugzilla-Version: 3.9 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: luca.dellatoffola@inf.ethz.ch X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: dev@poi.apache.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://issues.apache.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org https://issues.apache.org/bugzilla/show_bug.cgi?id=3D55611 --- Comment #7 from Luca Della Toffola --- Comment on attachment 30946 --> https://issues.apache.org/bugzilla/attachment.cgi?id=3D30946 Patch for poi-3.9 (synchronized) >diff -rupN -x '.*' poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.j= ava poi-3.9-patch/src/java/org/apache/poi/ss/usermodel/DateUtil.java >--- poi-3.9/src/java/org/apache/poi/ss/usermodel/DateUtil.java 2012-11-25 = 13:28:05.000000000 +0100 >+++ poi-3.9-patch/src/java/org/apache/poi/ss/usermodel/DateUtil.java 2013-= 10-17 17:32:51.000000000 +0200 >@@ -288,17 +288,31 @@ public class DateUtil { > * @param formatIndex The index of the format, eg from ExtendedFormat= Record.getFormatIndex > * @param formatString The format string, eg from FormatRecord.getFor= matString > * @see #isInternalDateFormat(int) >- */ >- public static boolean isADateFormat(int formatIndex, String formatStr= ing) { >- // First up, is this an internal date format? >- if(isInternalDateFormat(formatIndex)) { >- return true; >- } >- >- // If we didn't get a real string, it can't be >- if(formatString =3D=3D null || formatString.length() =3D=3D 0) { >- return false; >- } >+ */=20=20 >+ private static int lastFormatIndex =3D Integer.MIN_VALUE; >+ private static String lastFormatString =3D null; >+ private static boolean isADateFormatCache =3D false; >+=20=20=20=20 >+ public static synchronized boolean isADateFormat(int formatIndex, Str= ing formatString) { >+=20=20=20=20=20=20=20 >+ if (formatIndex =3D=3D lastFormatIndex && formatString !=3D null &= & formatString.equals(lastFormatString)) { >+ return isADateFormatCache; >+ } >+=20=20=20=20=20=20=20 >+ lastFormatIndex =3D formatIndex; >+ lastFormatString =3D formatString; >+=20=20=20=20=20=20=20 >+ // First up, is this an internal date format? >+ if (isInternalDateFormat(formatIndex)) { >+ isADateFormatCache =3D true; >+ return true; >+ } >+ >+ // If we didn't get a real string, it can't be >+ if(formatString =3D=3D null || formatString.length() =3D=3D 0) { >+ isADateFormatCache =3D false; >+ return false; >+ } >=20 > String fs =3D formatString; > /*if (false) { >@@ -348,6 +362,7 @@ public class DateUtil { >=20 > // short-circuit if it indicates elapsed time: [h], [m] or [s] > if(date_ptrn4.matcher(fs).matches()){ >+ isADateFormatCache =3D true; > return true; > } >=20 >@@ -367,7 +382,9 @@ public class DateUtil { > // Otherwise, check it's only made up, in any case, of: > // y m d h s - \ / , . : > // optionally followed by AM/PM >- return date_ptrn3.matcher(fs).matches(); >+ boolean result =3D date_ptrn3.matcher(fs).matches(); >+ isADateFormatCache =3D result; >+ return result; > } >=20 > /** --=20 You are receiving this mail because: You are the assignee for the bug.= --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org For additional commands, e-mail: dev-help@poi.apache.org