@@ -76,25 +76,29 @@ type FilePathIdSet = IntSet
76
76
data PathIdMap = PathIdMap
77
77
{ idToPathMap :: ! (FilePathIdMap ArtifactsLocation )
78
78
, pathToIdMap :: ! (HashMap NormalizedFilePath FilePathId )
79
+ , nextFreshId :: ! Int
79
80
}
80
81
deriving (Show , Generic )
81
82
82
83
instance NFData PathIdMap
83
84
84
85
emptyPathIdMap :: PathIdMap
85
- emptyPathIdMap = PathIdMap IntMap. empty HMS. empty
86
+ emptyPathIdMap = PathIdMap IntMap. empty HMS. empty 0
86
87
87
88
getPathId :: ArtifactsLocation -> PathIdMap -> (FilePathId , PathIdMap )
88
89
getPathId path m@ PathIdMap {.. } =
89
90
case HMS. lookup (artifactFilePath path) pathToIdMap of
90
91
Nothing ->
91
- let ! newId = FilePathId $ HMS. size pathToIdMap
92
+ let ! newId = FilePathId nextFreshId
92
93
in (newId, insertPathId path newId m)
93
94
Just id -> (id , m)
94
-
95
- insertPathId :: ArtifactsLocation -> FilePathId -> PathIdMap -> PathIdMap
96
- insertPathId path id PathIdMap {.. } =
97
- PathIdMap (IntMap. insert (getFilePathId id ) path idToPathMap) (HMS. insert (artifactFilePath path) id pathToIdMap)
95
+ where
96
+ insertPathId :: ArtifactsLocation -> FilePathId -> PathIdMap -> PathIdMap
97
+ insertPathId path id PathIdMap {.. } =
98
+ PathIdMap
99
+ (IntMap. insert (getFilePathId id ) path idToPathMap)
100
+ (HMS. insert (artifactFilePath path) id pathToIdMap)
101
+ (succ nextFreshId)
98
102
99
103
insertImport :: FilePathId -> Either ModuleParseError ModuleImports -> RawDependencyInformation -> RawDependencyInformation
100
104
insertImport (FilePathId k) v rawDepInfo = rawDepInfo { rawImports = IntMap. insert k v (rawImports rawDepInfo) }
0 commit comments