diff options
author | Janak Ramakrishnan <janakr@google.com> | 2015-06-16 17:46:36 +0000 |
---|---|---|
committer | John Field <jfield@google.com> | 2015-06-17 15:22:28 +0000 |
commit | b735d2f1819d924efed0ebe7816b12e0ce54e87b (patch) | |
tree | ff0ba97578b0ca44a5a7246044ad527f013a5124 /src/main/java/com/google/devtools/build | |
parent | 73dd2304ca974e8cde497a105680dc1c8b689966 (diff) |
Convert getTransitiveClosure to batch dep retrieval.
--
MOS_MIGRATED_REVID=96122155
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java index 6129c64a90..9c7a0bf6d9 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.query2; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -48,7 +49,6 @@ import com.google.devtools.build.skyframe.WalkableGraph; import com.google.devtools.build.skyframe.WalkableGraph.WalkableGraphFactory; import java.util.ArrayDeque; -import java.util.ArrayList; import java.util.Collection; import java.util.Deque; import java.util.HashMap; @@ -198,17 +198,14 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> { @Override public Set<Target> getTransitiveClosure(Set<Target> targets) { Set<Target> visited = new HashSet<>(); - List<Target> result = new ArrayList<>(targets); - int i = 0; - while (i < result.size()) { - for (Target dep : getFwdDeps(result.get(i))) { - if (visited.add(dep)) { - result.add(dep); - } - } - i++; + Collection<Target> current = targets; + while (!current.isEmpty()) { + Collection<Target> toVisit = Collections2.filter(current, + Predicates.not(Predicates.in(visited))); + current = getFwdDeps(toVisit); + visited.addAll(toVisit); } - return ImmutableSet.copyOf(result); + return ImmutableSet.copyOf(visited); } // Implemented with a breadth-first search. |