Avoid creating a temporary set in PrerequisiteArtifacts.get().
ImmutableSet#asList is able to avoid a copy.
@@ -17,13 +17,12 @@ package com.google.devtools.build.lib.analysis;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
/**
* Contains a sequence of prerequisite artifacts and supplies methods for filtering and reporting
@@ -55,11 +54,11 @@ public final class PrerequisiteArtifacts {
return new PrerequisiteArtifacts(
ruleContext, attributeName, prerequisites.get(0).getFilesToBuild().toList());
}
- Set<Artifact> result = new LinkedHashSet<>();
+ ImmutableSet.Builder<Artifact> result = ImmutableSet.builder();
for (FileProvider target : prerequisites) {
result.addAll(target.getFilesToBuild().toList());
}
- return new PrerequisiteArtifacts(ruleContext, attributeName, ImmutableList.copyOf(result));
+ return new PrerequisiteArtifacts(ruleContext, attributeName, result.build().asList());
}
public static NestedSet<Artifact> nestedSet(RuleContext ruleContext, String attributeName) {
