diff options
author | 2015-06-16 17:04:25 +0000 | |
---|---|---|
committer | 2015-06-17 15:22:25 +0000 | |
commit | 73dd2304ca974e8cde497a105680dc1c8b689966 (patch) | |
tree | b1787da06ce5ff5f547010653bc569f4ef44df97 /src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java | |
parent | 3bd26cd93a92814f94594272a9ad3e610798c8df (diff) |
Create batch versions of query environment methods getFwdDeps and getReverseDeps, and migrate DepsFunction and RdepsFunction to use them.
This makes our (unordered) results potentially dependent on the iteration order of hash sets, but what do we care?
--
MOS_MIGRATED_REVID=96117626
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java index 2b693eb8a7..25b1da7944 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java @@ -13,7 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.query2.engine; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; @@ -66,16 +68,12 @@ final class DepsFunction implements QueryFunction { // We need to iterate depthBound + 1 times. for (int i = 0; i <= depthBound; i++) { List<T> next = new ArrayList<>(); - for (T node : current) { - if (!visited.add(node)) { - // Already visited; if we see a node in a later round, then we don't need to visit it - // again, because the depth at which we see it at must be greater than or equal to the - // last visit. - continue; - } - - next.addAll(env.getFwdDeps(node)); - } + // Filter already visited nodes: if we see a node in a later round, then we don't need to + // visit it again, because the depth at which we see it at must be greater than or equal to + // the last visit. + next.addAll(env.getFwdDeps(Iterables.filter(current, + Predicates.not(Predicates.in(visited))))); + visited.addAll(current); if (next.isEmpty()) { // Exit when there are no more nodes to visit. break; |