diff options
author | Nathan Harmata <nharmata@google.com> | 2015-03-07 03:06:22 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-03-10 13:59:11 +0000 |
commit | c533acdef9d83a75a5aa8aef945f39af0d6c22ec (patch) | |
tree | 9f0199c05aac8616a1b70b6da0267b07a3d3a885 /src/main/java/com/google/devtools/build/lib/util/GroupedList.java | |
parent | 9b370024faa05f44d13dee1a42b35f7907afa991 (diff) |
Revert the recent changes that made some skyframe-internal data structures serializable; alternative graph implementations no longer need these.
--
MOS_MIGRATED_REVID=88003503
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/util/GroupedList.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/GroupedList.java | 39 |
1 files changed, 8 insertions, 31 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 a6642fe7ba..69ec97a62b 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 @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.collect.CompactHashSet; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -36,7 +35,7 @@ import java.util.Set; * <p>Despite the "list" name, it is an error for the same element to appear multiple times in the * list. Users are responsible for not trying to add the same element to a GroupedList twice. */ -public class GroupedList<T> implements Iterable<Iterable<T>>, Serializable { +public class GroupedList<T> implements Iterable<Iterable<T>> { // Total number of items in the list. At least elements.size(), but might be larger if there are // any nested lists. private int size = 0; @@ -85,27 +84,12 @@ public class GroupedList<T> implements Iterable<Iterable<T>>, Serializable { return elements.isEmpty(); } - private static final class EmptyList implements Serializable { - private static final EmptyList INSTANCE = new EmptyList(); - - private EmptyList() { - } - - @Override - public boolean equals(Object obj) { - return obj instanceof EmptyList; - } - - @Override - public int hashCode() { - return 42; - } - } + private static final Object EMPTY_LIST = new Object(); public Object compress() { switch (size()) { case 0: - return EmptyList.INSTANCE; + return EMPTY_LIST; case 1: return Iterables.getOnlyElement(elements); default: @@ -131,7 +115,7 @@ public class GroupedList<T> implements Iterable<Iterable<T>>, Serializable { } public static <E> GroupedList<E> create(Object compressed) { - if (compressed.equals(EmptyList.INSTANCE)) { + if (compressed == EMPTY_LIST) { return new GroupedList<>(); } if (compressed.getClass().isArray()) { @@ -173,18 +157,18 @@ public class GroupedList<T> implements Iterable<Iterable<T>>, Serializable { * iterator is needed here because, to optimize memory, we store single-element lists as elements * internally, and so they must be wrapped before they're returned. */ - private class GroupedIterator implements Iterator<Iterable<T>>, Serializable { - private int pos = 0; + private class GroupedIterator implements Iterator<Iterable<T>> { + private final Iterator<Object> iter = elements.iterator(); @Override public boolean hasNext() { - return pos < elements.size(); + return iter.hasNext(); } @SuppressWarnings("unchecked") // Cast of Object to List<T> or T. @Override public Iterable<T> next() { - Object obj = elements.get(pos++); + Object obj = iter.next(); if (obj instanceof List) { return (List<T>) obj; } @@ -260,13 +244,6 @@ public class GroupedList<T> implements Iterable<Iterable<T>>, Serializable { private List<E> currentGroup = null; private final Set<E> elements = CompactHashSet.create(); - private GroupedListHelper(GroupedList<E> groupedList) { - this.groupedList = new ArrayList<>(groupedList.elements); - for (Iterable<E> group : groupedList) { - Iterables.addAll(elements, group); - } - } - public GroupedListHelper() { // Optimize for short lists. groupedList = new ArrayList<>(1); |