// check cache
// We must search a immediate dominator.
//
// At first, we can ignore the older incoming nodes.
List<Node> candidates = new CopyOnWriteArrayList(target.incoming);
// compute backedges
for (Node node : candidates) {
if (target.backedges.contains(node)) {
candidates.remove(node);
}
}
int size = candidates.size();
switch (size) {
case 0: // this is root node
return null;
case 1: // only one incoming node
return candidates.get(0);
default: // multiple incoming nodes
Node candidate = candidates.get(0);
search: while (candidate != null) {
for (int i = 1; i < size; i++) {
if (!hasDominator(candidates.get(i), candidate, nodes)) {
candidate = getDominator(candidate, nodes);
continue search;
}
}
return candidate;