Small improvements to Java container handling as these have turned up in a
profile. No functional changes.

RELNOTES: None.
PiperOrigin-RevId: 245027678
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
index 3484906..4abf668 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
@@ -18,7 +18,6 @@
 import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.actions.ActionAnalysisMetadata.MiddlemanType;
 import com.google.devtools.build.lib.actions.cache.ActionCache;
 import com.google.devtools.build.lib.actions.cache.DigestUtils;
@@ -146,11 +145,13 @@
       Iterable<Artifact> actionInputs,
       MetadataHandler metadataHandler,
       boolean checkOutput) {
-    Iterable<Artifact> artifacts = checkOutput
-        ? Iterables.concat(action.getOutputs(), actionInputs)
-        : actionInputs;
     Map<String, FileArtifactValue> mdMap = new HashMap<>();
-    for (Artifact artifact : artifacts) {
+    if (checkOutput) {
+      for (Artifact artifact : action.getOutputs()) {
+        mdMap.put(artifact.getExecPathString(), getMetadataMaybe(metadataHandler, artifact));
+      }
+    }
+    for (Artifact artifact : actionInputs) {
       mdMap.put(artifact.getExecPathString(), getMetadataMaybe(metadataHandler, artifact));
     }
     return !DigestUtils.fromMetadata(mdMap).equals(entry.getFileDigest());
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java b/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
index 38408bc..dfcfd7a 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
@@ -286,9 +286,7 @@
     // Profiling showed that MD5 engine instantiation was a hotspot, so create one instance for
     // this computation to amortize its cost.
     Fingerprint fp = new Fingerprint();
-    for (Map.Entry<String, FileArtifactValue> entry : mdMap.entrySet()) {
-      xorWith(result, getDigest(fp, entry.getKey(), entry.getValue()));
-    }
+    mdMap.forEach((key, value) -> xorWith(result, getDigest(fp, key, value)));
     return new Md5Digest(result);
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
index f6579c6..59237ed 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
@@ -194,7 +194,7 @@
       Preconditions.checkState(!env.valuesMissing(), "%s %s", action, state);
     }
     CheckInputResults checkedInputs = null;
-    Iterable<SkyKey> inputDepKeys =
+    Iterable<? extends SkyKey> inputDepKeys =
         toKeys(
             state.allInputs.getAllInputs(),
             action.discoversInputs() ? action.getMandatoryInputs() : null);
@@ -852,27 +852,19 @@
     return null;
   }
 
-  private static Iterable<SkyKey> toKeys(
+  private static Iterable<? extends SkyKey> toKeys(
       Iterable<Artifact> inputs, Iterable<Artifact> mandatoryInputs) {
     if (mandatoryInputs == null) {
       // This is a non inputs-discovering action, so no need to distinguish mandatory from regular
       // inputs.
-      return Iterables.transform(
-          inputs,
-          new Function<Artifact, SkyKey>() {
-            @Override
-            public SkyKey apply(Artifact artifact) {
-              return ArtifactSkyKey.key(artifact, true);
-            }
-          });
-    } else {
-      Collection<SkyKey> discoveredArtifacts = new HashSet<>();
-      Set<Artifact> mandatory = Sets.newHashSet(mandatoryInputs);
-      for (Artifact artifact : inputs) {
-        discoveredArtifacts.add(ArtifactSkyKey.key(artifact, mandatory.contains(artifact)));
-      }
-      return discoveredArtifacts;
+      return inputs;
     }
+    Collection<SkyKey> discoveredArtifacts = new HashSet<>();
+    Set<Artifact> mandatory = Sets.newHashSet(mandatoryInputs);
+    for (Artifact artifact : inputs) {
+      discoveredArtifacts.add(ArtifactSkyKey.key(artifact, mandatory.contains(artifact)));
+    }
+    return discoveredArtifacts;
   }
 
   private static class CheckInputResults {