From 74e7203d68d30b724ddfbcef2743ff180065c9d6 Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Thu, 2 Nov 2023 15:34:06 +0100 Subject: [PATCH] Try some minor efficiency improvements --- .../de/fraunhofer/aisec/cpg/helpers/EOGWorklist.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/EOGWorklist.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/EOGWorklist.kt index 1c5d322f758..1d6df22a46d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/EOGWorklist.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/EOGWorklist.kt @@ -135,7 +135,7 @@ open class State : IdentityHashMap>() { // upper bound this[newNode] = newLatticeElement.lub(current) } else { - this[newNode] = newLatticeElement.duplicate() + this[newNode] = newLatticeElement } return true } @@ -147,13 +147,15 @@ open class State : IdentityHashMap>() { */ class Worklist() { /** A mapping of nodes to the state which is currently available there. */ - var globalState: MutableMap> = mutableMapOf() + var globalState = IdentityHashMap>() private set /** A list of all nodes which have already been visited. */ private val alreadySeen = IdentitySet() - constructor(globalState: MutableMap> = mutableMapOf()) : this() { + constructor( + globalState: IdentityHashMap> = IdentityHashMap>() + ) : this() { this.globalState = globalState } @@ -242,7 +244,9 @@ inline fun iterateEOG( startState: State, transformation: (K, State, Worklist) -> State ): State? { - val worklist = Worklist(mutableMapOf(Pair(startNode, startState))) + val initialState = IdentityHashMap>() + initialState[startNode] = startState + val worklist = Worklist(initialState) worklist.push(startNode, startState) while (worklist.isNotEmpty()) { @@ -273,7 +277,7 @@ inline fun , N : Any, V> iterateEOG( startState: State, transformation: (K, State, Worklist) -> State ): State? { - val globalState = mutableMapOf>() + val globalState = IdentityHashMap>() for (startEdge in startEdges) { globalState[startEdge] = startState }