From 0d3378ed0f2c8ee79862ce2045fa837fadb3f503 Mon Sep 17 00:00:00 2001 From: ajurkowski Date: Thu, 23 Jul 2020 14:23:41 -0700 Subject: [PATCH] Apply Java Code Clarity suggestions to StarlarkCustomCommandLine. Apply comments about wrong usage of `HashMap::HashMap(int)` constructor and not initializing the declared variable in place. PiperOrigin-RevId: 322865605 --- .../analysis/starlark/StarlarkCustomCommandLine.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java index eca345ea044f6d..ba10d0e5cd0aad 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Interner; +import com.google.common.collect.Sets; import com.google.devtools.build.lib.actions.ActionKeyContext; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander; @@ -214,8 +215,8 @@ private int eval( // It's safe to uniquify at this stage, any transformations after this // will ensure continued uniqueness of the values if ((features & UNIQUIFY) != 0) { - HashSet seen = new HashSet<>(stringValues.size()); int count = stringValues.size(); + HashSet seen = Sets.newHashSetWithExpectedSize(count); int addIndex = 0; for (int i = 0; i < count; ++i) { String val = stringValues.get(i); @@ -295,11 +296,8 @@ private static boolean isDirectory(Object object) { private static List expandDirectories( Artifact.ArtifactExpander artifactExpander, List originalValues) throws CommandLineExpansionException { - List expandedValues; - int n = originalValues.size(); - expandedValues = new ArrayList<>(n); - for (int i = 0; i < n; ++i) { - Object object = originalValues.get(i); + List expandedValues = new ArrayList<>(originalValues.size()); + for (Object object : originalValues) { if (isDirectory(object)) { Artifact artifact = (Artifact) object; if (artifact.isTreeArtifact()) { @@ -345,7 +343,7 @@ private int addToFingerprint( StarlarkCallable mapEach = ((features & HAS_MAP_EACH) != 0) ? (StarlarkCallable) arguments.get(argi++) : null; if ((features & IS_NESTED_SET) != 0) { - NestedSet values = (NestedSet) arguments.get(argi++); + NestedSet values = (NestedSet) arguments.get(argi++); if (mapEach != null) { CommandLineItem.MapFn commandLineItemMapFn = new CommandLineItemMapEachAdaptor(mapEach, location, starlarkSemantics);