Skip to content

Commit 308da09

Browse files
committed
Refactor renderScript to eliminate set/list conversions
1 parent a813b85 commit 308da09

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/Stack/Ghci.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,17 +676,23 @@ renderScript ::
676676
-- ^ Files targets with unknown GHC options.
677677
-> GhciScript
678678
renderScript pkgs mainFile onlyMain extraFiles = do
679-
let addPhase = cmdAdd $ S.fromList (map Left allModules ++ addMain)
680-
addMain = maybe [] (L.singleton . Right) mainFile
681-
modulePhase = cmdModule $ S.fromList allModules
682-
allModules = nubOrd $ concatMap (M.keys . (.modules)) pkgs
679+
let allModules = S.unions $ map (M.keysSet . (.modules)) pkgs
680+
addMain = maybe S.empty (S.singleton . Right) mainFile
681+
-- If a main module is to be :add-ed, the context will be set to
682+
-- it:
683+
addPhase = cmdAdd $ S.map Left allModules <> addMain
684+
modulePhase = cmdModule allModules
683685
case getFileTargets pkgs <> extraFiles of
684686
[] ->
685687
if onlyMain
686688
then
687689
if isJust mainFile
688-
then cmdAdd (S.fromList addMain)
689-
else mempty
690+
then
691+
-- If a main module is to be :add-ed, the context will be set to
692+
-- it:
693+
cmdAdd addMain
694+
else
695+
mempty
690696
else addPhase <> modulePhase
691697
fileTargets -> cmdAdd (S.fromList (map Right fileTargets))
692698

0 commit comments

Comments
 (0)