Skip to content

Commit a4fafc2

Browse files
committed
Optimise literate code - avoid a redundant read
1 parent 1c1f554 commit a4fafc2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Development/IDE/Core/Preprocessor.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ import Data.Maybe
3333
-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
3434
preprocessor :: GhcMonad m => FilePath -> Maybe StringBuffer -> ExceptT [FileDiagnostic] m (StringBuffer, DynFlags)
3535
preprocessor filename mbContents = do
36-
contents <- liftIO $ maybe (hGetStringBuffer filename) return mbContents
37-
let isOnDisk = isNothing mbContents
38-
39-
-- unlit content if literate Haskell ending
40-
(isOnDisk, contents) <- if isLiterate filename
41-
then do
36+
-- Perform unlit
37+
(isOnDisk, contents) <- if isLiterate filename then do
4238
dflags <- getDynFlags
4339
newcontent <- liftIO $ runLhs dflags filename mbContents
4440
return (False, newcontent)
45-
else return (isOnDisk, contents)
41+
else do
42+
contents <- liftIO $ maybe (hGetStringBuffer filename) return mbContents
43+
let isOnDisk = isNothing mbContents
44+
return (isOnDisk, contents)
4645

46+
-- Perform cpp
4747
dflags <- ExceptT $ parsePragmasIntoDynFlags filename contents
4848
if not $ xopt LangExt.Cpp dflags then
4949
return (contents, dflags)

0 commit comments

Comments
 (0)