diff options
author | 2015-09-23 17:30:04 +0000 | |
---|---|---|
committer | 2015-09-24 14:18:46 +0000 | |
commit | df0531fad8fc0288c21f5672aa59907362ae0ff5 (patch) | |
tree | b836a359a54977b891397c1a85293d1d7d854fe4 /src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java | |
parent | 784ffc06ea463912eca747a3c3a796d649232650 (diff) |
Allow Skylark import lookup values to be computed inline in order to avoid reifying them in the Skyframe graph.
--
MOS_MIGRATED_REVID=103758591
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java b/src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java new file mode 100644 index 0000000000..c765ddf767 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skyframe/CycleUtils.java @@ -0,0 +1,41 @@ +// Copyright 2015 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.skyframe; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.util.Pair; + +/** Simple utility for separating path and cycle from a combined iterable. */ +class CycleUtils { + private CycleUtils() {} + + static <S> Pair<ImmutableList<S>, ImmutableList<S>> splitIntoPathAndChain( + Predicate<S> startOfCycle, Iterable<S> pathAndCycle) { + boolean inPathToCycle = true; + ImmutableList.Builder<S> pathToCycleBuilder = ImmutableList.builder(); + ImmutableList.Builder<S> cycleBuilder = ImmutableList.builder(); + for (S elt : pathAndCycle) { + if (startOfCycle.apply(elt)) { + inPathToCycle = false; + } + if (inPathToCycle) { + pathToCycleBuilder.add(elt); + } else { + cycleBuilder.add(elt); + } + } + return Pair.of(pathToCycleBuilder.build(), cycleBuilder.build()); + } +} |