@@ -3,36 +3,21 @@ package io.shiftleft.codepropertygraph.cpgloading
3
3
import flatgraph .*
4
4
import io .shiftleft .proto .cpg .Cpg .CpgStruct
5
5
6
+ import scala .collection .mutable
6
7
import scala .jdk .CollectionConverters .*
7
8
8
- /** Mutable datastructure to preserve mapping between proto and cpg nodes during ProtoToCpg import.
9
+ /** Mutable data structure to preserve mapping between proto and cpg nodes during ProtoToCpg import.
9
10
*
10
11
* Context: we need to run two passes: 1) add nodes and 2) set node properties and add edges (this is due to
11
12
* flatgraph-specific implementation details)
12
13
*
13
- * Because of that, we need to remember the mapping from proto node id to gnode. Typically that's just a plain mapping,
14
- * but there's one special case for TYPE nodes: some (parallel) frontends create duplicate TYPE nodes which we need to
15
- * deduplicate...
14
+ * Because of that, we need to remember the mapping from proto node id to gnode. Typically, that's just a plain
15
+ * mapping. But there's one special case for TYPE nodes: some (parallel) frontends create duplicate TYPE nodes which we
16
+ * need to deduplicate...
16
17
*/
17
18
class ProtoToGraphNodeMappings {
18
- private var protoNodeIdToGNode = Map .empty[Long , DNode ]
19
- private var typeFullNameToGNode = Map .empty[String , DNode ]
20
-
21
- def addAll (other : ProtoToGraphNodeMappings ): Unit = {
22
- val intersection1 = this .protoNodeIdToGNode.keySet.intersect(other.protoNodeIdToGNode.keySet)
23
- val intersection2 = this .typeFullNameToGNode.keySet.intersect(other.typeFullNameToGNode.keySet)
24
- assert(
25
- intersection1.isEmpty,
26
- s " unexpected duplicate entries in protoNodeIdToGNode mappings. protoNodeIds: $intersection1"
27
- )
28
- assert(
29
- intersection2.isEmpty,
30
- s " unexpected duplicate entries in typeFullNameToGNode mappings. FullNames: $intersection2"
31
- )
32
-
33
- this .protoNodeIdToGNode = this .protoNodeIdToGNode ++ other.protoNodeIdToGNode
34
- this .typeFullNameToGNode = this .typeFullNameToGNode ++ other.typeFullNameToGNode
35
- }
19
+ private val protoNodeIdToGNode = mutable.LongMap .empty[DNode ]
20
+ private val typeFullNameToGNode = mutable.Map .empty[String , DNode ]
36
21
37
22
def add (protoNode : CpgStruct .Node , node : DNode ): Unit = {
38
23
protoNodeIdToGNode += protoNode.getKey -> node
@@ -48,7 +33,7 @@ class ProtoToGraphNodeMappings {
48
33
}
49
34
}
50
35
51
- /** This will fail hard if the DiffGraph hasn't been applied yet, which is the assumption for it's use case. In other
36
+ /** This will fail hard if the DiffGraph hasn't been applied yet, which is the assumption for its use case. In other
52
37
* words, we specifically don't want to invoke `find(protoNode).flatMap(_.storedRef)` here
53
38
*/
54
39
def findGNode (protoNode : CpgStruct .Node ): Option [GNode ] =
0 commit comments