From: Reimar Döffinger Date: Sun, 15 Oct 2017 08:25:05 +0000 (+0200) Subject: Cache compiled patterns. X-Git-Url: http://gitweb.fperrin.net/?p=DictionaryPC.git;a=commitdiff_plain;h=5ce5941fa2f306dab71d74db377235c685b70a74 Cache compiled patterns. --- diff --git a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java index 850dede..c1cb09f 100644 --- a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java +++ b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java @@ -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;