From c195995ac7d1a101fda8ebd612877d06fe4efc7f Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Mon, 30 Jan 2017 21:31:56 +0300 Subject: [PATCH] [file-history] use continue outer statement instead of a boolean flag to simplify code understanding --- .../intellij/vcs/log/graph/utils/DfsUtil.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/DfsUtil.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/DfsUtil.java index 5d4427290e1a..6927706f0728 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/DfsUtil.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/DfsUtil.java @@ -54,6 +54,7 @@ public class DfsUtil { Stack> stack = new Stack<>(); stack.push(new Pair<>(start, true)); // commit + direction of travel + outer: while (!stack.empty()) { int currentNode = stack.peek().first; boolean down = stack.peek().second; @@ -62,32 +63,26 @@ public class DfsUtil { visitor.enterNode(currentNode); } - boolean found = false; for (int nextNode : graph.getNodes(currentNode, down ? LiteLinearGraph.NodeFilter.DOWN : LiteLinearGraph.NodeFilter.UP)) { if (!visited.get(nextNode)) { stack.push(new Pair<>(nextNode, down)); - found = true; - break; + continue outer; } } - if (!found) { - if (!visitedInSameDirection.get(currentNode)) { - visitedInSameDirection.set(currentNode, true); - visitor.exitNode(currentNode); - } - for (int nextNode : graph.getNodes(currentNode, down ? LiteLinearGraph.NodeFilter.UP : LiteLinearGraph.NodeFilter.DOWN)) { - if (!visited.get(nextNode)) { - stack.push(new Pair<>(nextNode, !down)); - found = true; - break; - } + if (!visitedInSameDirection.get(currentNode)) { + visitedInSameDirection.set(currentNode, true); + visitor.exitNode(currentNode); + } + + for (int nextNode : graph.getNodes(currentNode, down ? LiteLinearGraph.NodeFilter.UP : LiteLinearGraph.NodeFilter.DOWN)) { + if (!visited.get(nextNode)) { + stack.push(new Pair<>(nextNode, !down)); + continue outer; } } - if (!found) { - stack.pop(); - } + stack.pop(); } }