From ea755497ee809c09b0fca23c571ad1a3a369d9dd Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 10 Apr 2020 10:19:01 +0100 Subject: [PATCH] Optimize DataFlowAnalyzer by reducing the size of the initial work list Signed-off-by: Graham --- .../dev/openrs2/deob/analysis/DataFlowAnalyzer.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt b/deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt index 917c20e04d..7ff70e0f3c 100644 --- a/deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt +++ b/deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt @@ -42,18 +42,20 @@ abstract class DataFlowAnalyzer(owner: String, private val method: MethodNode } fun analyze() { - for (node in graph.vertexSet()) { - outSets[node] = createInitialSet() - } + val initialSet = createInitialSet() + + val workList = LinkedHashSet() + workList += graph.vertexSet().filter { vertex -> graph.inDegreeOf(vertex) == 0 } - val workList = LinkedHashSet(graph.vertexSet()) while (true) { val node = workList.removeFirstOrNull() ?: break - val predecessors = graph.incomingEdgesOf(node).map { edge -> outSets[graph.getEdgeSource(edge)]!! } + val predecessors = graph.incomingEdgesOf(node).map { edge -> + outSets[graph.getEdgeSource(edge)] ?: initialSet + } val inSet = if (predecessors.isEmpty()) { - createInitialSet() + initialSet } else { predecessors.reduce(this::join) }