force sofar calculation
authorJoey Hess <joeyh@joeyh.name>
Thu, 8 Dec 2016 20:28:07 +0000 (16:28 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 8 Dec 2016 20:28:07 +0000 (16:28 -0400)
This could avoid a memory leak. It would only happen when
the meter didn't look at sofar.

Utility/Metered.hs

index b80d3ae3f97f7587ed6104b8d380a4e2c323463b..e21e18cf1433dae97a9affd05b4a68a639278a27 100644 (file)
@@ -5,7 +5,7 @@
  - License: BSD-2-clause
  -}
 
-{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE TypeSynonymInstances, BangPatterns #-}
 
 module Utility.Metered where
 
@@ -93,7 +93,7 @@ meteredWrite' meterupdate h = go zeroBytesProcessed . L.toChunks
        go sofar [] = return sofar
        go sofar (c:cs) = do
                S.hPut h c
-               let sofar' = addBytesProcessed sofar $ S.length c
+               let !sofar' = addBytesProcessed sofar $ S.length c
                meterupdate sofar'
                go sofar' cs
 
@@ -138,7 +138,7 @@ hGetMetered h wantsize meterupdate = lazyRead zeroBytesProcessed
                                hClose h
                                return $ L.empty
                        else do
-                               let sofar' = addBytesProcessed sofar (S.length c)
+                               let !sofar' = addBytesProcessed sofar (S.length c)
                                meterupdate sofar'
                                if keepgoing (fromBytesProcessed sofar')
                                        then do