Pull #2495: Performance-Optimization: Do not recompile Pattern for each file/line

This commit is contained in:
Fabian Loewner 2015-11-01 00:38:18 +01:00 committed by Roman Ivanov
parent 6354f009e8
commit 8f3da64f6d
1 changed files with 9 additions and 1 deletions

View File

@ -50,6 +50,8 @@ class DetectorOptions {
private boolean ignoreCase;
/** Used to determine whether to suppress a detected match. */
private MatchSuppressor suppressor = NeverSuppress.INSTANCE;
/** Pattern created from format. Lazily initialized. */
private Pattern pattern;
/**
* Creates an instance.
@ -69,6 +71,7 @@ class DetectorOptions {
*/
public DetectorOptions setFormat(String format) {
this.format = format;
pattern = null;
return this;
}
@ -119,6 +122,7 @@ class DetectorOptions {
*/
public DetectorOptions setIgnoreCase(boolean ignore) {
ignoreCase = ignore;
pattern = null;
return this;
}
@ -175,11 +179,15 @@ class DetectorOptions {
* @return the pattern to use when matching.
*/
public Pattern getPattern() {
if (pattern != null) {
return pattern;
}
int options = compileFlags;
if (ignoreCase) {
options |= Pattern.CASE_INSENSITIVE;
}
return Pattern.compile(format, options);
pattern = Pattern.compile(format, options);
return pattern;
}
}