Small performance improvement. Make ReachablePredicate a singleton so that we don't end up creating a new Predicate object for every scope.
@@ -64,8 +64,7 @@ class CheckUnreachableCode extends AbstractPreOrderCallback implements ScopedCal
compiler.report(t.makeError(n, UNREACHABLE_CODE));
// From now on, we are going to assume the user fixed the error and not
// give more warning related to code section reachable from this node.
- new GraphReachability<>(
- t.getControlFlowGraph()).recompute(n);
+ new GraphReachability<>(t.getControlFlowGraph()).recompute(n);
// Saves time by not traversing children.
return false;
@@ -75,17 +74,15 @@ class CheckUnreachableCode extends AbstractPreOrderCallback implements ScopedCal
}
private void initScope(ControlFlowGraph<Node> controlFlowGraph) {
- new GraphReachability<>(
- controlFlowGraph, new ReachablePredicate()).compute(
- controlFlowGraph.getEntry().getValue());
+ new GraphReachability<>(controlFlowGraph, REACHABLE)
+ .compute(controlFlowGraph.getEntry().getValue());
}
@Override
- public void exitScope(NodeTraversal t) {
- }
+ public void exitScope(NodeTraversal t) {}
- private static final class ReachablePredicate implements
- Predicate<EdgeTuple<Node, ControlFlowGraph.Branch>> {
+ private static final Predicate<EdgeTuple<Node, ControlFlowGraph.Branch>> REACHABLE =
+ new Predicate<EdgeTuple<Node, ControlFlowGraph.Branch>>() {
@Override
public boolean apply(EdgeTuple<Node, Branch> input) {
@@ -106,5 +103,5 @@ class CheckUnreachableCode extends AbstractPreOrderCallback implements ScopedCal
}
return true;
}
- }
+ };
}
