mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Bug 565553 - Improve performance of build command parsers with large number of files
Compile a pattern ahead of time and early return. The first pattern is used to trim extra characters that are not contained within the actual option pattern. If this first pattern doesn't match, there is no point in continuing because it is a superset. Times before/after, only counting AbstractOptionParser.parseOption LLVM before: 4289ms, after: 622ms Change-Id: Id40fc9a35359c39aea00ba14813ffe6c343158fc Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
a9b67d0828
commit
e933f46289
1 changed files with 8 additions and 4 deletions
|
@ -145,7 +145,6 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
|||
*/
|
||||
protected static abstract class AbstractOptionParser {
|
||||
private final int kind;
|
||||
private final String patternStr;
|
||||
private final Pattern pattern;
|
||||
private final String nameExpression;
|
||||
private final String valueExpression;
|
||||
|
@ -153,6 +152,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
|||
|
||||
private String parsedName;
|
||||
private String parsedValue;
|
||||
private final Pattern removeExtraFileNamePattern;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -168,12 +168,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
|||
public AbstractOptionParser(int kind, String pattern, String nameExpression, String valueExpression,
|
||||
int extraFlag) {
|
||||
this.kind = kind;
|
||||
this.patternStr = pattern;
|
||||
this.nameExpression = nameExpression;
|
||||
this.valueExpression = valueExpression;
|
||||
this.extraFlag = extraFlag;
|
||||
|
||||
this.pattern = Pattern.compile(pattern);
|
||||
this.removeExtraFileNamePattern = Pattern.compile("(" + pattern + ").*"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,8 +225,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
|||
*/
|
||||
public boolean parseOption(String optionString) {
|
||||
// get rid of extra text at the end (for example file name could be confused for an argument)
|
||||
@SuppressWarnings("nls")
|
||||
String option = optionString.replaceFirst("(" + patternStr + ").*", "$1");
|
||||
Matcher matcherRemoveExtra = removeExtraFileNamePattern.matcher(optionString);
|
||||
String option = optionString;
|
||||
if (!matcherRemoveExtra.matches()) {
|
||||
return false;
|
||||
}
|
||||
option = matcherRemoveExtra.group(1);
|
||||
|
||||
Matcher matcher = pattern.matcher(option);
|
||||
boolean isMatch = matcher.matches();
|
||||
|
|
Loading…
Add table
Reference in a new issue