Commit 32939559 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Improve style and performance of PackageIndex.dependencyClosure

Keep the completed set as another PackageIndex rather than a list.
We want to return an index at the end anyway and in the mean time
we want to do lots of lookups to see if we've visited previously.
parent f7fbf11b
......@@ -272,20 +272,18 @@ dependencyClosure :: PackageFixedDeps pkg
-> [PackageIdentifier]
-> Either (PackageIndex pkg)
[(pkg, [PackageIdentifier])]
dependencyClosure index pkgids0 = case closure [] [] pkgids0 of
(completed, []) -> Left $ fromList completed
(completed, _) -> Right $ brokenPackages (fromList completed)
dependencyClosure index pkgids0 = case closure mempty [] pkgids0 of
(completed, []) -> Left completed
(completed, _) -> Right (brokenPackages completed)
where
closure completed failed [] = (completed, failed)
closure completed failed [] = (completed, failed)
closure completed failed (pkgid:pkgids) = case lookupPackageId index pkgid of
Nothing -> closure completed (pkgid:failed) pkgids
-- TODO: use more effecient test here:
Just pkg | packageId pkg `elem` map packageId completed
-> closure completed failed pkgids
| otherwise
-> closure (pkg:completed) failed pkgids'
where pkgids' = depends pkg ++ pkgids
Nothing -> closure completed (pkgid:failed) pkgids
Just pkg -> case lookupPackageId completed (packageId pkg) of
Just _ -> closure completed failed pkgids
Nothing -> closure completed' failed pkgids'
where completed' = insert pkg completed
pkgids' = depends pkg ++ pkgids
-- | Given a package index where we assume we want to use all the packages
-- (use 'dependencyClosure' if you need to get such a index subset) find out
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment