Skip to content

Commit a1fc61c

Browse files
committed
optimize buildImmediateDepsFingerprintMap
1 parent be60d4d commit a1fc61c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

ghcide/src/Development/IDE/Import/DependencyInformation.hs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -419,25 +419,18 @@ instance Show NamedModuleDep where
419419

420420

421421
buildImmediateDepsFingerprintMap :: FilePathIdMap FilePathIdSet -> FilePathIdMap Fingerprint -> FilePathIdMap Fingerprint
422-
buildImmediateDepsFingerprintMap modulesDeps shallowFingers = go keys IntMap.empty
423-
where
424-
keys = IntMap.keys shallowFingers
425-
go :: [IntSet.Key] -> FilePathIdMap Fingerprint -> FilePathIdMap Fingerprint
426-
go keys acc =
427-
case keys of
428-
[] -> acc
429-
k : ks ->
430-
if IntMap.member k acc
431-
-- already in the map, so we can skip
432-
then go ks acc
433-
-- not in the map, so we need to add it
434-
else
435-
let -- get the dependencies of the current key
436-
deps = IntSet.toList $ IntMap.findWithDefault IntSet.empty k modulesDeps
437-
-- combine the fingerprints of the dependencies with the current key
438-
combinedFingerprints = Util.fingerprintFingerprints $ map (shallowFingers IntMap.!) (k:deps)
439-
in -- add the combined fingerprints to the accumulator
440-
go ks (IntMap.insert k combinedFingerprints acc)
422+
buildImmediateDepsFingerprintMap modulesDeps shallowFingers =
423+
IntMap.fromList
424+
$ map
425+
( \k ->
426+
( k,
427+
Util.fingerprintFingerprints $
428+
map
429+
(shallowFingers IntMap.!)
430+
(k : IntSet.toList (IntMap.findWithDefault IntSet.empty k modulesDeps))
431+
)
432+
)
433+
$ IntMap.keys shallowFingers
441434

442435
-- | Build a map from file path to its full fingerprint.
443436
-- The fingerprint is depend on both the fingerprints of the file and all its dependencies.

0 commit comments

Comments
 (0)