mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-23 12:35:07 +00:00
Trie is thread-safe, no need to recreate one every time
This commit is contained in:
@@ -15,6 +15,8 @@ public class FeedCleaner {
|
|||||||
|
|
||||||
private static final Pattern DOCTYPE_PATTERN = Pattern.compile("<!DOCTYPE[^>]*>", Pattern.CASE_INSENSITIVE);
|
private static final Pattern DOCTYPE_PATTERN = Pattern.compile("<!DOCTYPE[^>]*>", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
private final Trie trie = Trie.builder().ignoreOverlaps().addKeywords(HtmlEntities.HTML_ENTITIES).build();
|
||||||
|
|
||||||
public String clean(String xml) {
|
public String clean(String xml) {
|
||||||
xml = removeCharactersBeforeFirstXmlTag(xml);
|
xml = removeCharactersBeforeFirstXmlTag(xml);
|
||||||
xml = removeInvalidXmlCharacters(xml);
|
xml = removeInvalidXmlCharacters(xml);
|
||||||
@@ -52,7 +54,7 @@ public class FeedCleaner {
|
|||||||
// Create a buffer sufficiently large that re-allocations are minimized.
|
// Create a buffer sufficiently large that re-allocations are minimized.
|
||||||
StringBuilder sb = new StringBuilder(source.length() << 1);
|
StringBuilder sb = new StringBuilder(source.length() << 1);
|
||||||
|
|
||||||
Collection<Emit> emits = Trie.builder().ignoreOverlaps().addKeywords(HtmlEntities.HTML_ENTITIES).build().parseText(source);
|
Collection<Emit> emits = trie.parseText(source);
|
||||||
|
|
||||||
int prevIndex = 0;
|
int prevIndex = 0;
|
||||||
for (Emit emit : emits) {
|
for (Emit emit : emits) {
|
||||||
|
|||||||
Reference in New Issue
Block a user