aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2016-10-25 00:11:37 +0000
committerGravatar John Cater <jcater@google.com>2016-10-25 20:16:34 +0000
commitdade5e171bb8a82f267513e47ccb63aa7d3d4517 (patch)
tree45275a1d8fca4dc122b83966ce27bd60bc4d97ca /src/main
parent11730a017e6f79bbd07a6ed29d6d05dc1c87d345 (diff)
If a group of deps has only one unique element, store it bare.
Not storing it bare both breaks equality comparison for GroupedList and uses more space. -- Change-Id: Iaf4f88908ecf4293cfc31dbd896f46e1da3b4184 Reviewed-on: https://bazel-review.googlesource.com/#/c/6850/ MOS_MIGRATED_REVID=137099785
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/util/GroupedList.java8
1 files changed, 4 insertions, 4 deletions
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 a6f9fbe683..9babacff2b 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
@@ -66,12 +66,14 @@ public class GroupedList<T> implements Iterable<Collection<T>> {
// Iterables.getFirst will return null, and null is not instanceof List.
Preconditions.checkState(!(Iterables.getFirst(helper.elements, null) instanceof List),
"Cannot make grouped list of lists: %s", helper);
- Set<T> uniquifier = CompactHashSet.createWithExpectedSize(helper.groupedList.size());
+ Set<T> uniquifier = CompactHashSet.createWithExpectedSize(helper.elements.size());
for (Object item : helper.groupedList) {
if (item instanceof List) {
// Optimize for the case that elements in this list are unique.
ImmutableList.Builder<T> dedupedList = null;
List<T> list = (List<T>) item;
+ Preconditions.checkState(
+ list.size() > 1, "Helper should have compressed small list %s properly", list);
for (int i = 0; i < list.size(); i++) {
T elt = list.get(i);
if (!uniquifier.add(elt)) {
@@ -87,9 +89,7 @@ public class GroupedList<T> implements Iterable<Collection<T>> {
elements.add(list);
} else {
List<T> filteredList = dedupedList.build();
- if (!filteredList.isEmpty()) {
- elements.add(filteredList);
- }
+ addItem(filteredList, elements);
}
} else if (uniquifier.add((T) item)) {
elements.add(item);