[devirtualization] Used hash set to handle multi-edges
This commit is contained in:
+24
-5
@@ -120,8 +120,26 @@ internal object Devirtualization {
|
|||||||
|
|
||||||
private val symbolTable = moduleDFG.symbolTable
|
private val symbolTable = moduleDFG.symbolTable
|
||||||
|
|
||||||
|
// TODO: Make custom hashtable.
|
||||||
|
class IntHashSet : Iterable<Int> {
|
||||||
|
private val hashSet = HashSet<Int>()
|
||||||
|
val size get() = hashSet.size
|
||||||
|
fun isEmpty() = size == 0
|
||||||
|
fun add(x: Int) = hashSet.add(x)
|
||||||
|
|
||||||
|
override operator fun iterator(): Iterator<Int> = Itr()
|
||||||
|
|
||||||
|
private inner class Itr : Iterator<Int> {
|
||||||
|
private val itr = hashSet.iterator()
|
||||||
|
override fun hasNext() = itr.hasNext()
|
||||||
|
|
||||||
|
override fun next() = itr.next()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sealed class Node(val id: Int) {
|
sealed class Node(val id: Int) {
|
||||||
var directEdges: IntArrayList? = null
|
var directEdges: IntHashSet? = null
|
||||||
var reversedEdges: IntArrayList? = null
|
var reversedEdges: IntArrayList? = null
|
||||||
|
|
||||||
var directCastEdges: MutableList<CastEdge>? = null
|
var directCastEdges: MutableList<CastEdge>? = null
|
||||||
@@ -137,10 +155,11 @@ internal object Devirtualization {
|
|||||||
val multiNodeSize get() = multiNodeEnd - multiNodeStart
|
val multiNodeSize get() = multiNodeEnd - multiNodeStart
|
||||||
|
|
||||||
fun addEdge(node: Node) {
|
fun addEdge(node: Node) {
|
||||||
if (directEdges == null) directEdges = IntArrayList()
|
if (directEdges == null) directEdges = IntHashSet()
|
||||||
node.directEdges!!.add(node.id)
|
if (directEdges!!.add(node.id)) {
|
||||||
if (node.reversedEdges == null) node.reversedEdges = IntArrayList()
|
if (node.reversedEdges == null) node.reversedEdges = IntArrayList()
|
||||||
node.reversedEdges!!.add(id)
|
node.reversedEdges!!.add(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCastEdge(edge: CastEdge) {
|
fun addCastEdge(edge: CastEdge) {
|
||||||
|
|||||||
Reference in New Issue
Block a user