Use work lists to speed up DataFlowAnalyzer

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 95c5ad0ffe
commit 286be9cdd3
  1. 15
      deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt

@ -1,5 +1,6 @@
package dev.openrs2.deob.analysis package dev.openrs2.deob.analysis
import dev.openrs2.util.collect.removeFirstOrNull
import org.jgrapht.Graph import org.jgrapht.Graph
import org.jgrapht.graph.DefaultEdge import org.jgrapht.graph.DefaultEdge
import org.jgrapht.graph.EdgeReversedGraph import org.jgrapht.graph.EdgeReversedGraph
@ -45,11 +46,10 @@ abstract class DataFlowAnalyzer<T>(owner: String, private val method: MethodNode
outSets[node] = createInitialSet() outSets[node] = createInitialSet()
} }
var changed: Boolean val workList = LinkedHashSet<Int>(graph.vertexSet())
do { while (true) {
changed = false val node = workList.removeFirstOrNull() ?: break
for (node in graph.vertexSet()) {
val predecessors = graph.incomingEdgesOf(node).map { edge -> outSets[graph.getEdgeSource(edge)]!! } val predecessors = graph.incomingEdgesOf(node).map { edge -> outSets[graph.getEdgeSource(edge)]!! }
val inSet = if (predecessors.isEmpty()) { val inSet = if (predecessors.isEmpty()) {
@ -64,9 +64,12 @@ abstract class DataFlowAnalyzer<T>(owner: String, private val method: MethodNode
if (outSets[node] != outSet) { if (outSets[node] != outSet) {
outSets[node] = outSet outSets[node] = outSet
changed = true
for (edge in graph.outgoingEdgesOf(node)) {
val successor = graph.getEdgeTarget(edge)
workList += successor
}
} }
} }
} while (changed)
} }
} }

Loading…
Cancel
Save