From eb76d16dde650b8c2474d369f5c306744d66de38 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 9 Feb 2020 11:52:48 -0500 Subject: [PATCH] faster package item nesting conversion --- src/Convert/NestPI.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Convert/NestPI.hs b/src/Convert/NestPI.hs index 238897d..24612ed 100644 --- a/src/Convert/NestPI.hs +++ b/src/Convert/NestPI.hs @@ -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