diff options
author | michajlo <michajlo@google.com> | 2017-08-08 00:33:26 +0200 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-08-08 13:03:22 +0200 |
commit | f3e91b2d140011bcf53e44528b59f559766a20e4 (patch) | |
tree | 41bb5e33b6d701d3e89cf8bf7a8c33655560d392 /src/main/java/com/google/devtools/build/lib | |
parent | 49b4bd3db59a8007bf9bdc6c9ec1fa95ce2e88b9 (diff) |
Use Sets.new...WithExpectedSize to presize some collections
It was noticed that we missed this in commments on
https://github.com/bazelbuild/bazel/commit/2266a6f88030e7121031db19fb5efc3fc7cb149c.
This a better job of preventing resizes than the former, with the caveat that
it may create a larger collection than is necessary.
PiperOrigin-RevId: 164520695
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java index c622340c3a..726672de97 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java @@ -17,6 +17,7 @@ import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.packages.Attribute; @@ -203,7 +204,7 @@ abstract class TransitiveBaseTraversalFunction<TProcessedTargets> implements Sky if (target instanceof OutputFile) { Rule rule = ((OutputFile) target).getGeneratingRule(); List<Label> visibilityLabels = visitTargetVisibility(target); - HashSet<Label> result = new HashSet<>(visibilityLabels.size() + 1); + HashSet<Label> result = Sets.newHashSetWithExpectedSize(visibilityLabels.size() + 1); result.add(rule.getLabel()); result.addAll(visibilityLabels); return result; @@ -212,7 +213,8 @@ abstract class TransitiveBaseTraversalFunction<TProcessedTargets> implements Sky } else if (target instanceof Rule) { List<Label> visibilityLabels = visitTargetVisibility(target); Collection<Label> ruleLabels = visitRule(target); - HashSet<Label> result = new HashSet<>(visibilityLabels.size() + ruleLabels.size()); + HashSet<Label> result = + Sets.newHashSetWithExpectedSize(visibilityLabels.size() + ruleLabels.size()); result.addAll(visibilityLabels); result.addAll(ruleLabels); return result; |