From 58fb174b809447225647ff7aa7a9d164bd03309d Mon Sep 17 00:00:00 2001 From: Daniel Fischer Date: Wed, 20 Oct 2010 09:11:11 +0000 Subject: [PATCH] FIX #4334 Make selector thunks visible to GHC to fix a space leak in lines. --- Data/List.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Data/List.hs b/Data/List.hs index 221a340..0e4e621 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -1038,10 +1038,23 @@ product l = prod l 1 -- characters. The resulting strings do not contain newlines. lines :: String -> [String] lines "" = [] +#ifdef __GLASGOW_HASKELL__ +-- Somehow GHC doesn't detect the selector thunks in the below code, +-- so s' keeps a reference to the first line via the pair and we have +-- a space leak (cf. #4334). +-- So we need to make GHC see the selector thunks with a trick. +lines s = cons (case break (== '\n') s of + (l, s') -> (l, case s' of + [] -> [] + _:s'' -> lines s'')) + where + cons ~(h, t) = h : t +#else lines s = let (l, s') = break (== '\n') s in l : case s' of [] -> [] (_:s'') -> lines s'' +#endif -- | 'unlines' is an inverse operation to 'lines'. -- It joins lines, after appending a terminating newline to each. -- 1.7.10.4