[Git][ghc/ghc][master] Remove potential space leak from Data.List.transpose
Marge Bot
gitlab at gitlab.haskell.org
Wed Sep 2 19:55:37 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
c30cc0e9 by David Feuer at 2020-09-02T15:55:31-04:00
Remove potential space leak from Data.List.transpose
Previously, `transpose` produced a list of heads
and a list of tails independently. This meant that
a function using only some heads, and only some tails,
could potentially leak space. Use `unzip` to work
around the problem by producing pairs and selector
thunks instead. Time and allocation behavior will
be worse, but there should be no more leak potential.
- - - - -
1 changed file:
- libraries/base/Data/OldList.hs
Changes:
=====================================
libraries/base/Data/OldList.hs
=====================================
@@ -550,7 +550,13 @@ intercalate xs xss = concat (intersperse xs xss)
transpose :: [[a]] -> [[a]]
transpose [] = []
transpose ([] : xss) = transpose xss
-transpose ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (xs : [ t | (_:t) <- xss])
+transpose ((x:xs) : xss) = (x : hds) : transpose (xs : tls)
+ where
+ -- We tie the calculations of heads and tails together
+ -- to prevent heads from leaking into tails and vice versa.
+ -- unzip makes the selector thunk arrangements we need to
+ -- ensure everything gets cleaned up properly.
+ (hds, tls) = unzip [(hd, tl) | (hd:tl) <- xss]
-- | The 'partition' function takes a predicate a list and returns
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c30cc0e9c3704b24ad0f6d9a0199bf8b5835bd40
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c30cc0e9c3704b24ad0f6d9a0199bf8b5835bd40
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200902/b3304f1c/attachment.html>
More information about the ghc-commits
mailing list