Skip to content

Commit a87a8da

Browse files
committed
[duplicated subtitle] perf(SubtitleDeduplicator): compile TTML <p> pattern once for efficiency
- Replace defineTtmlSubtitlePattern() method with a static final Pattern - getTtmlMatcher() now reuses the precompiled pattern instead of recompiling each call - Improves performance when processing multiple subtitles without changing behavior
1 parent cc6e119 commit a87a8da

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

app/src/main/java/org/schabi/newpipe/util/subtitle/SubtitleDeduplicator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,13 @@ private static boolean stringIsNullOrEmpty(final String inputString) {
372372
return false;
373373
}
374374

375-
private static Pattern defineTtmlSubtitlePattern() {
376-
return Pattern.compile(
377-
"<p[^>]*begin=\"([^\"]+)\"[^>]*end=\"([^\"]+)\"[^>]*>(.*?)</p>",
378-
Pattern.DOTALL
379-
);
380-
}
375+
private static final Pattern TTML_PARAGRAPH_PATTERN = Pattern.compile(
376+
"<p[^>]*begin=\"([^\"]+)\"[^>]*end=\"([^\"]+)\"[^>]*>(.*?)</p>",
377+
Pattern.DOTALL
378+
);
381379

382380
private static Matcher getTtmlMatcher(final String subtitleContent) {
383-
final Pattern pattern = defineTtmlSubtitlePattern();
381+
final Pattern pattern = TTML_PARAGRAPH_PATTERN;
384382
return pattern.matcher(subtitleContent);
385383
}
386384

0 commit comments

Comments
 (0)