poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1744005 - /poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
Date Mon, 16 May 2016 10:02:13 GMT
Author: kiwiwings
Date: Mon May 16 10:02:13 2016
New Revision: 1744005

URL: http://svn.apache.org/viewvc?rev=1744005&view=rev
Log:
Reduce calls to utf-related methods - the integration test took ages because of poc-shared-strings.xlsx

Modified:
    poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java

Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java?rev=1744005&r1=1744004&r2=1744005&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
Mon May 16 10:02:13 2016
@@ -18,6 +18,8 @@ package org.apache.poi.xssf.eventusermod
 
 import java.io.InputStream;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.xssf.eventusermodel.XLSX2CSV;
@@ -92,11 +94,26 @@ public class FromHowTo {
 	 * See org.xml.sax.helpers.DefaultHandler javadocs
 	 */
 	private static class SheetHandler extends DefaultHandler {
-		private SharedStringsTable sst;
+		private final SharedStringsTable sst;
 		private String lastContents;
 		private boolean nextIsString;
 		private boolean inlineStr;
+		private final LruCache<Integer,String> lruCache = new LruCache<Integer,String>(50);
 
+		private static class LruCache<A,B> extends LinkedHashMap<A, B> {
+		    private final int maxEntries;
+
+		    public LruCache(final int maxEntries) {
+		        super(maxEntries + 1, 1.0f, true);
+		        this.maxEntries = maxEntries;
+		    }
+
+		    @Override
+		    protected boolean removeEldestEntry(final Map.Entry<A, B> eldest) {
+		        return super.size() > maxEntries;
+		    }
+		}
+		
 		private SheetHandler(SharedStringsTable sst) {
 			this.sst = sst;
 		}
@@ -121,8 +138,12 @@ public class FromHowTo {
 			// Process the last contents as required.
 			// Do now, as characters() may be called more than once
 			if(nextIsString) {
-				int idx = Integer.parseInt(lastContents);
-				lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
+				Integer idx = Integer.valueOf(lastContents);
+				lastContents = lruCache.get(idx);
+				if (lastContents == null && !lruCache.containsKey(idx)) {
+				    lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
+				    lruCache.put(idx, lastContents);
+				}
 				nextIsString = false;
 			}
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message