From bd2417bc9912b672ebcd69d0879031cb3324ca6d Mon Sep 17 00:00:00 2001 From: djasper Date: Wed, 13 Jan 2021 02:27:01 -0800 Subject: [PATCH] Pre-concatenate private and public modular headers. For transitive information, we aren't generally interested in whether something is a public or a private header, we only need to be able to distinguish modular and textual headers. This simplifies code that operates on the transitive data structures and makes it more efficient. RELNOTES: None. PiperOrigin-RevId: 351545030 --- .../lib/rules/cpp/CcCompilationContext.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java index cdd488e1b4c5b5..83fe985bdd21fb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java @@ -433,13 +433,7 @@ public IncludeScanningHeaderData.Builder createIncludeScanningHeaderData( for (HeaderInfo transitiveHeaderInfo : transitiveHeaderInfos) { boolean isModule = createModularHeaders && transitiveHeaderInfo.getModule(usePic) != null; handleHeadersForIncludeScanning( - transitiveHeaderInfo.modularPublicHeaders, - pathToLegalArtifact, - treeArtifacts, - isModule, - modularHeaders); - handleHeadersForIncludeScanning( - transitiveHeaderInfo.modularPrivateHeaders, + transitiveHeaderInfo.modularHeaders, pathToLegalArtifact, treeArtifacts, isModule, @@ -456,8 +450,7 @@ public IncludeScanningHeaderData.Builder createIncludeScanningHeaderData( return null; } transitiveHeaderCount.compareAndSet(-1, pathToLegalArtifact.size()); - removeArtifactsFromSet(modularHeaders, headerInfo.modularPublicHeaders); - removeArtifactsFromSet(modularHeaders, headerInfo.modularPrivateHeaders); + removeArtifactsFromSet(modularHeaders, headerInfo.modularHeaders); removeArtifactsFromSet(modularHeaders, headerInfo.textualHeaders); return new IncludeScanningHeaderData.Builder(pathToLegalArtifact, modularHeaders); } @@ -476,16 +469,11 @@ public Collection computeUsedModules( } // Not using range-based for loops here as often there is exactly one element in this list // and the amount of garbage created by SingletonImmutableList.iterator() is significant. - for (int i = 0; i < transitiveHeaderInfo.modularPublicHeaders.size(); i++) { - Artifact header = transitiveHeaderInfo.modularPublicHeaders.get(i); - if (includes.contains(header)) { - modules.add(module); - } - } - for (int i = 0; i < transitiveHeaderInfo.modularPrivateHeaders.size(); i++) { - Artifact header = transitiveHeaderInfo.modularPrivateHeaders.get(i); + for (int i = 0; i < transitiveHeaderInfo.modularHeaders.size(); i++) { + Artifact header = transitiveHeaderInfo.modularHeaders.get(i); if (includes.contains(header)) { modules.add(module); + break; } } } @@ -539,8 +527,7 @@ public Iterable getDirectModuleMaps() { */ ImmutableSet getHeaderModuleSrcs() { return new ImmutableSet.Builder() - .addAll(headerInfo.modularPublicHeaders) - .addAll(headerInfo.modularPrivateHeaders) + .addAll(headerInfo.modularHeaders) .addAll(headerInfo.textualHeaders) .build(); } @@ -1113,6 +1100,9 @@ public static final class HeaderInfo { /** All private header files that are compiled into this module. */ private final ImmutableList modularPrivateHeaders; + /** All header files that are compiled into this module. */ + private final ImmutableList modularHeaders; + /** All textual header files that are contained in this module. */ private final ImmutableList textualHeaders; @@ -1133,6 +1123,8 @@ public static final class HeaderInfo { this.picHeaderModule = picHeaderModule; this.modularPublicHeaders = modularPublicHeaders; this.modularPrivateHeaders = modularPrivateHeaders; + this.modularHeaders = + ImmutableList.copyOf(Iterables.concat(modularPublicHeaders, modularPrivateHeaders)); this.textualHeaders = textualHeaders; this.deps = deps; }