Skip to content

Commit

Permalink
Pre-concatenate private and public modular headers. For transitive in…
Browse files Browse the repository at this point in the history
…formation,

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
  • Loading branch information
djasper-gh authored and copybara-github committed Jan 13, 2021
1 parent b0aa8e6 commit bd2417b
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -476,16 +469,11 @@ public Collection<Artifact.DerivedArtifact> 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;
}
}
}
Expand Down Expand Up @@ -539,8 +527,7 @@ public Iterable<Artifact> getDirectModuleMaps() {
*/
ImmutableSet<Artifact> getHeaderModuleSrcs() {
return new ImmutableSet.Builder<Artifact>()
.addAll(headerInfo.modularPublicHeaders)
.addAll(headerInfo.modularPrivateHeaders)
.addAll(headerInfo.modularHeaders)
.addAll(headerInfo.textualHeaders)
.build();
}
Expand Down Expand Up @@ -1113,6 +1100,9 @@ public static final class HeaderInfo {
/** All private header files that are compiled into this module. */
private final ImmutableList<Artifact> modularPrivateHeaders;

/** All header files that are compiled into this module. */
private final ImmutableList<Artifact> modularHeaders;

/** All textual header files that are contained in this module. */
private final ImmutableList<Artifact> textualHeaders;

Expand All @@ -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;
}
Expand Down

0 comments on commit bd2417b

Please sign in to comment.