Allow constructing a dependency group with an initial capacity in GroupedListHelper

RELNOTES: None
PiperOrigin-RevId: 152687516
diff --git a/src/main/java/com/google/devtools/build/lib/util/GroupedList.java b/src/main/java/com/google/devtools/build/lib/util/GroupedList.java
index 9babacf..5fe9838 100644
--- a/src/main/java/com/google/devtools/build/lib/util/GroupedList.java
+++ b/src/main/java/com/google/devtools/build/lib/util/GroupedList.java
@@ -432,6 +432,16 @@
       currentGroup = new ArrayList<>();
     }
 
+    /**
+     * Starts a group with an initial capacity. All elements added until {@link #endGroup} will be
+     * in the same group. Each call of startGroup must be paired with a following {@link #endGroup}
+     * call. Any duplicate elements added to this group will be silently deduplicated.
+     */
+    public void startGroup(int expectedGroupSize) {
+      Preconditions.checkState(currentGroup == null, this);
+      currentGroup = new ArrayList<>(expectedGroupSize);
+    }
+
     /** Ends a group started with {@link #startGroup}. */
     public void endGroup() {
       Preconditions.checkNotNull(currentGroup);