Optimize DataFlowAnalyzer by reducing the size of the initial work list

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 2ac0e7eb50
commit ea755497ee
  1. 14
      deob/src/main/java/dev/openrs2/deob/analysis/DataFlowAnalyzer.kt

@ -42,18 +42,20 @@ abstract class DataFlowAnalyzer<T>(owner: String, private val method: MethodNode
}
fun analyze() {
for (node in graph.vertexSet()) {
outSets[node] = createInitialSet()
}
val initialSet = createInitialSet()
val workList = LinkedHashSet<Int>()
workList += graph.vertexSet().filter { vertex -> graph.inDegreeOf(vertex) == 0 }
val workList = LinkedHashSet<Int>(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)
}

Loading…
Cancel
Save