Skip to content

Commit

Permalink
Apply Java Code Clarity suggestions to StarlarkCustomCommandLine.
Browse files Browse the repository at this point in the history
Apply comments about wrong usage of `HashMap::HashMap(int)` constructor and not
initializing the declared variable in place.

PiperOrigin-RevId: 322865605
  • Loading branch information
alexjski authored and copybara-github committed Jul 23, 2020
1 parent 3f895e2 commit 0d3378e
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> seen = new HashSet<>(stringValues.size());
int count = stringValues.size();
HashSet<String> seen = Sets.newHashSetWithExpectedSize(count);
int addIndex = 0;
for (int i = 0; i < count; ++i) {
String val = stringValues.get(i);
Expand Down Expand Up @@ -295,11 +296,8 @@ private static boolean isDirectory(Object object) {
private static List<Object> expandDirectories(
Artifact.ArtifactExpander artifactExpander, List<Object> originalValues)
throws CommandLineExpansionException {
List<Object> expandedValues;
int n = originalValues.size();
expandedValues = new ArrayList<>(n);
for (int i = 0; i < n; ++i) {
Object object = originalValues.get(i);
List<Object> expandedValues = new ArrayList<>(originalValues.size());
for (Object object : originalValues) {
if (isDirectory(object)) {
Artifact artifact = (Artifact) object;
if (artifact.isTreeArtifact()) {
Expand Down Expand Up @@ -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<Object> commandLineItemMapFn =
new CommandLineItemMapEachAdaptor(mapEach, location, starlarkSemantics);
Expand Down

0 comments on commit 0d3378e

Please sign in to comment.