Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2020-09-27 00:59:59 -0400
committerMarc-André Laperle2020-10-04 14:29:11 -0400
commit08e8e57162f5a7c52f90380bc03bb6896e19d095 (patch)
treeadd486a52520cfeed5f210203015a43c80cac730 /windows/org.eclipse.cdt.msw.build/src/org/eclipse
parent379e30038237c6db8af1cf84b1bdd3d5f31da59c (diff)
downloadorg.eclipse.cdt-08e8e57162f5a7c52f90380bc03bb6896e19d095.tar.gz
org.eclipse.cdt-08e8e57162f5a7c52f90380bc03bb6896e19d095.tar.xz
org.eclipse.cdt-08e8e57162f5a7c52f90380bc03bb6896e19d095.zip
Bug 565553 - Improve performance of build command parsers with large number of files
Narrow down parsers based on option string Instead of trying to match all patterns one by one, we can check the start of the option string to be parsed and narrow down which pattern (parsers) should be used. Doing so is much less elegant code-wise as we are "unrolling" the beginning of the patterns by hand, but it gives a good speed up. Around 300ms saved with a test of LLVM code base (~50% of parseOption time) and much larger gains on much larger projects or course. Change-Id: I9e841e7233078d6e38ad08943d98966d0e3c661e Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
Diffstat (limited to 'windows/org.eclipse.cdt.msw.build/src/org/eclipse')
-rw-r--r--windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/core/MSVCBuildCommandParser.java71
1 files changed, 66 insertions, 5 deletions
diff --git a/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/core/MSVCBuildCommandParser.java b/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/core/MSVCBuildCommandParser.java
index 8089a8e6271..d45314ee0e6 100644
--- a/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/core/MSVCBuildCommandParser.java
+++ b/windows/org.eclipse.cdt.msw.build/src/org/eclipse/cdt/msw/build/core/MSVCBuildCommandParser.java
@@ -11,6 +11,8 @@
package org.eclipse.cdt.msw.build.core;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -93,12 +95,22 @@ public class MSVCBuildCommandParser extends AbstractBuildCommandParser implement
}
@SuppressWarnings("nls")
- static final AbstractOptionParser[] optionParsers = { new MSVCIncludePathOptionParser("(-|/)I\\s*\"(.*)\"", "$2"),
- new MSVCIncludePathOptionParser("(-|/)I\\s*([^\\s\"]*)", "$2"),
+ static final AbstractOptionParser[] includeOptionParsers = {
+ new MSVCIncludePathOptionParser("(-|/)I\\s*\"(.*)\"", "$2"),
+ new MSVCIncludePathOptionParser("(-|/)I\\s*([^\\s\"]*)", "$2"), };
+
+ @SuppressWarnings("nls")
+ static final AbstractOptionParser[] forceIncludeOptionParsers = {
new MSVCForceIncludePathOptionParser("(-|/)FI\\s*\"(.*)\"", "$2"),
- new MSVCForceIncludePathOptionParser("(-|/)FI\\s*([^\\s\"]*)", "$2"),
+ new MSVCForceIncludePathOptionParser("(-|/)FI\\s*([^\\s\"]*)", "$2"), };
+
+ @SuppressWarnings("nls")
+ static final AbstractOptionParser[] msvcIncludeOptionParsers = {
new ClangCLMSVCSystemPathOptionParser("(-|/)imsvc\\s*\"(.*)\"", "$2"),
- new ClangCLMSVCSystemPathOptionParser("(-|/)imsvc\\s*([^\\s\"]*)", "$2"),
+ new ClangCLMSVCSystemPathOptionParser("(-|/)imsvc\\s*([^\\s\"]*)", "$2"), };
+
+ @SuppressWarnings("nls")
+ static final AbstractOptionParser[] defineOptionParsers = {
// /D "FOO=bar"
new MSVCMacroOptionParser("(-|/)D\\s*\"([^=]+)=(.*)\"", "$2", "$3"),
// /D FOO="bar"
@@ -108,12 +120,28 @@ public class MSVCBuildCommandParser extends AbstractBuildCommandParser implement
// /D FOO
new MSVCMacroOptionParser("(-|/)D\\s*([^\\s=\"]+)", "$2", "1"),
// /D"FOO"
- new MSVCMacroOptionParser("(-|/)D\\s*\"([^\\s=\"]+)\"", "$2", "1"),
+ new MSVCMacroOptionParser("(-|/)D\\s*\"([^\\s=\"]+)\"", "$2", "1"), };
+
+ @SuppressWarnings("nls")
+ static final AbstractOptionParser[] undefineOptionParsers = {
// /U FOO
new MacroOptionParser("(-|/)U\\s*([^\\s=\"]+)", "$2", ICSettingEntry.UNDEFINED),
// /U "FOO"
new MacroOptionParser("(-|/)U\\s*\"(.*?)\"", "$2", ICSettingEntry.UNDEFINED) };
+ static final AbstractOptionParser[] emptyParsers = new AbstractOptionParser[0];
+
+ static final AbstractOptionParser[] optionParsers;
+ static {
+ List<AbstractOptionParser> parsers = new ArrayList<>(Arrays.asList(includeOptionParsers));
+ Collections.addAll(parsers, defineOptionParsers);
+ Collections.addAll(parsers, msvcIncludeOptionParsers);
+ Collections.addAll(parsers, forceIncludeOptionParsers);
+ Collections.addAll(parsers, undefineOptionParsers);
+
+ optionParsers = parsers.toArray(new AbstractOptionParser[0]);
+ }
+
/**
* "foo" or "C:\foo\\"
*
@@ -147,6 +175,39 @@ public class MSVCBuildCommandParser extends AbstractBuildCommandParser implement
return optionParsers;
}
+ @SuppressWarnings("nls")
+ @Override
+ protected AbstractOptionParser[] getOptionParsers(String optionToParse) {
+ if (optionToParse.length() <= 1) {
+ return emptyParsers;
+ }
+
+ // Skip - or /, we know it's there with the OPTIONS_PATTERN
+ String optionName = optionToParse.substring(1);
+
+ if (optionName.startsWith("I")) {
+ return includeOptionParsers;
+ }
+
+ if (optionName.startsWith("D")) {
+ return defineOptionParsers;
+ }
+
+ if (optionName.startsWith("imsvc")) {
+ return msvcIncludeOptionParsers;
+ }
+
+ if (optionName.startsWith("FI")) {
+ return forceIncludeOptionParsers;
+ }
+
+ if (optionName.startsWith("U")) {
+ return undefineOptionParsers;
+ }
+
+ return emptyParsers;
+ }
+
@Override
public MSVCBuildCommandParser cloneShallow() throws CloneNotSupportedException {
return (MSVCBuildCommandParser) super.cloneShallow();

Back to the top