diff options
author | Michajlo Matijkiw <michajlo@google.com> | 2017-03-14 16:56:05 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-03-14 19:51:47 +0000 |
commit | aea4e5c9b569144b58194538005aa5d525c34d2e (patch) | |
tree | 320976881431164cf50d57e6e1359de6d5f80d5c /src/main | |
parent | bf34ec10c021636dc3577eb1e6357f04149f9e97 (diff) |
Avoid expanding NestedSets in IterablesChain Builder
Iterables.isEmpty winds up expanding the NestedSet, which isn't cheap.
--
PiperOrigin-RevId: 150079225
MOS_MIGRATED_REVID=150079225
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/collect/IterablesChain.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/IterablesChain.java b/src/main/java/com/google/devtools/build/lib/collect/IterablesChain.java index 69abf331cb..0286798e2a 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/IterablesChain.java +++ b/src/main/java/com/google/devtools/build/lib/collect/IterablesChain.java @@ -18,7 +18,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; - +import com.google.devtools.build.lib.collect.nestedset.NestedSet; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -77,7 +77,11 @@ public final class IterablesChain<T> implements Iterable<T> { */ public Builder<T> add(Iterable<? extends T> iterable) { CollectionUtils.checkImmutable(iterable); - if (!Iterables.isEmpty(iterable)) { + // Avoid unnecessarily expanding a NestedSet. + boolean isEmpty = iterable instanceof NestedSet + ? ((NestedSet<?>) iterable).isEmpty() + : Iterables.isEmpty(iterable); + if (!isEmpty) { iterables.add(iterable); } return this; |