Skip to content

Commit bdfe231

Browse files
committed
Using identity set of mutable set
1 parent f182173 commit bdfe231

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ImportResolver.kt

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ import de.fraunhofer.aisec.cpg.graph.namespaces
3838
import de.fraunhofer.aisec.cpg.graph.scopes.NameScope
3939
import de.fraunhofer.aisec.cpg.graph.scopes.Scope
4040
import de.fraunhofer.aisec.cpg.graph.translationUnit
41+
import de.fraunhofer.aisec.cpg.helpers.IdentitySet
4142
import de.fraunhofer.aisec.cpg.helpers.SubgraphWalker
4243
import de.fraunhofer.aisec.cpg.helpers.Util.errorWithFileLocation
44+
import de.fraunhofer.aisec.cpg.helpers.identitySetOf
45+
import de.fraunhofer.aisec.cpg.helpers.toIdentitySet
4346
import de.fraunhofer.aisec.cpg.passes.Pass.Companion.log
4447
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
4548
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy.COMPONENTS_LEAST_IMPORTS
4649
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy.TRANSLATION_UNITS_LEAST_IMPORTS
50+
import java.util.IdentityHashMap
4751

4852
/**
4953
* This class holds the information about import dependencies between nodes that represent some kind
@@ -53,12 +57,12 @@ import de.fraunhofer.aisec.cpg.processing.strategy.Strategy.TRANSLATION_UNITS_LE
5357
* symbols and imports ideally. This is stored in [sorted] and is automatically computed the fist
5458
* time someone accesses the property.
5559
*/
56-
class ImportDependencies<T : Node>(modules: MutableList<T>) : HashMap<T, MutableSet<T>>() {
60+
class ImportDependencies<T : Node>(modules: MutableList<T>) : IdentityHashMap<T, IdentitySet<T>>() {
5761

5862
init {
5963
// Populate the map with all modules so that we have an entry in our list
6064
// for all
61-
this += modules.map { Pair(it, mutableSetOf()) }
65+
this += modules.map { Pair(it, identitySetOf()) }
6266
}
6367

6468
/**
@@ -70,7 +74,7 @@ class ImportDependencies<T : Node>(modules: MutableList<T>) : HashMap<T, Mutable
7074

7175
/** Adds a dependency from [importer] to [imported]. */
7276
fun add(importer: T, imported: T): Boolean {
73-
var list = this.computeIfAbsent(importer) { mutableSetOf<T>() }
77+
var list = this.computeIfAbsent(importer) { identitySetOf<T>() }
7478
var added = list.add(imported)
7579

7680
return added
@@ -80,11 +84,11 @@ class ImportDependencies<T : Node>(modules: MutableList<T>) : HashMap<T, Mutable
8084
* A work-list, which contains a local copy of our dependency map, so that we can remove items
8185
* from it while determining the order.
8286
*/
83-
class WorkList<T : Node>(start: ImportDependencies<T>) : HashMap<T, MutableSet<T>>() {
87+
class WorkList<T : Node>(start: ImportDependencies<T>) : IdentityHashMap<T, IdentitySet<T>>() {
8488

8589
init {
8690
// Populate the work-list with a copy of the import dependency map
87-
this += start.map { Pair(it.key, it.value.toMutableSet()) }
91+
this += start.map { Pair(it.key, it.value.toIdentitySet()) }
8892
}
8993

9094
/**

0 commit comments

Comments
 (0)