diff options
author | 2018-05-14 02:47:58 -0700 | |
---|---|---|
committer | 2018-05-14 02:49:04 -0700 | |
commit | 43181c9363473baed3de071a320e1da23ac45d26 (patch) | |
tree | 0e1dd64c144d462cfca78a2161a5d1b6ac412e16 /src/main/java | |
parent | 7fae58d19189fd4d9209c2e5fd12cc47ec08818e (diff) |
Add a fast path for validating include directives. Most -isystem directives are
actually added for cc_library's include-attribute. For these, the same path is
present on the command line, but also ignored. For N of those directives, we
currently do O(N^2) prefix checks, which is unnecessarily expensive.
RELNOTES: None.
PiperOrigin-RevId: 196477307
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 5c1c57af9f..5d456784e4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -19,6 +19,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionOwner; import com.google.devtools.build.lib.actions.Artifact; @@ -481,7 +482,7 @@ public class CppCompileActionBuilder { } private void verifyActionIncludePaths(CppCompileAction action, Consumer<String> errorReporter) { - Iterable<PathFragment> ignoredDirs = action.getValidationIgnoredDirs(); + ImmutableSet<PathFragment> ignoredDirs = ImmutableSet.copyOf(action.getValidationIgnoredDirs()); // We currently do not check the output of: // - getQuoteIncludeDirs(): those only come from includes attributes, and are checked in // CcCommon.getIncludeDirsFromIncludesAttribute(). @@ -491,7 +492,11 @@ public class CppCompileActionBuilder { Iterable<PathFragment> includePathsToVerify = Iterables.concat(action.getIncludeDirs(), action.getSystemIncludeDirs()); for (PathFragment includePath : includePathsToVerify) { - if (FileSystemUtils.startsWithAny(includePath, ignoredDirs)) { + // includePathsToVerify contains all paths that are added as -isystem directive on the command + // line, most of which are added for include directives in the CcCompilationContext and are + // thus also in ignoredDirs. The hash lookup prevents this from becoming O(N^2) for these. + if (ignoredDirs.contains(includePath) + || FileSystemUtils.startsWithAny(includePath, ignoredDirs)) { continue; } // One starting ../ is okay for getting to a sibling repository. |