faster package item nesting conversion

This commit is contained in:
Zachary Snow 2020-02-09 11:52:48 -05:00
parent 48f84a9ed4
commit eb76d16dde
1 changed files with 6 additions and 5 deletions

View File

@ -7,7 +7,6 @@
module Convert.NestPI (convert) where
import Control.Monad.Writer
import Data.List (isPrefixOf)
import Data.List.Unique (complex)
import qualified Data.Set as Set
@ -56,10 +55,8 @@ convertDescription pis (orig @ Part{}) =
, collectTypesM $ collectNestedTypesM collectTypenamesM
, collectExprsM $ collectNestedExprsM collectIdentsM
]
neededPIs = Set.difference
(Set.union usedPIs $
Set.filter (isPrefixOf "import ") $ Set.fromList $ map fst pis)
existingPIs
neededPIs = Set.difference (Set.union usedPIs imports) existingPIs
imports = Set.fromList $ map fst $ filter (isImport . snd) pis
uniq l = l' where (l', _, _) = complex l
newItems = uniq $ map MIPackageItem $ map snd $
filter (\(x, _) -> Set.member x neededPIs) pis
@ -108,3 +105,7 @@ piName (Decl (CommentDecl _)) = Nothing
piName (Import x y) = Just $ show $ Import x y
piName (Export _) = Nothing
piName (Directive _) = Nothing
isImport :: PackageItem -> Bool
isImport Import{} = True
isImport _ = False