]> gitweb.fperrin.net Git - DictionaryPC.git/commitdiff
Cache compiled patterns.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 15 Oct 2017 08:25:05 +0000 (10:25 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 15 Oct 2017 08:25:05 +0000 (10:25 +0200)
src/com/hughes/android/dictionary/engine/WiktionarySplitter.java

index 850dedee2018c7fcf2ea4bb558edefdfb27551a7..c1cb09feee66380514a1de7a4aca2a933855e2a6 100644 (file)
@@ -114,6 +114,14 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
 
     String lastPageTitle = null;
     int pageCount = 0;
+    Pattern endPatterns[] = new Pattern[100];
+
+    private Pattern getEndPattern(int depth) {
+        if (endPatterns[depth] == null)
+            endPatterns[depth] = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE);
+        return endPatterns[depth];
+    }
+
     private void endPage() {
         final String title = titleBuilder.toString();
         lastPageTitle = title;
@@ -200,7 +208,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
                 if (heading.indexOf("Translingual") != -1) {
                     // Find end.
                     final int depth = startMatcher.group(1).length();
-                    final Pattern endPattern = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE);
+                    final Pattern endPattern = getEndPattern(depth);
 
                     final Matcher endMatcher = endPattern.matcher(text);
                     if (endMatcher.find()) {
@@ -214,7 +222,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
 
                     // Find end.
                     final int depth = startMatcher.group(1).length();
-                    final Pattern endPattern = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE);
+                    final Pattern endPattern = getEndPattern(depth);
 
                     final Matcher endMatcher = endPattern.matcher(text);
                     final int end;