force sofar calculation

This could avoid a memory leak. It would only happen when
the meter didn't look at sofar.
This commit is contained in:
Joey Hess 2016-12-08 16:28:07 -04:00
parent c6972cb914
commit 2ad06ded7e
No known key found for this signature in database
GPG key ID: C910D9222512E3C7

View 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