optimisation

IORef rather than MVar sped up benchmark mentioned in last commit to
13.0s.

This makes me wonder if changing the interface to not need the IORef
either would improve speed further.
This commit is contained in:
Joey Hess 2021-02-10 16:38:33 -04:00
parent f44d4704c6
commit dc9376feeb
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -28,7 +28,7 @@ import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as L
import Control.DeepSeq
import Control.Exception (evaluate)
import Control.Concurrent.MVar
import Data.IORef
data Hash
= MD5Hash
@ -280,15 +280,11 @@ md5Hasher = mkHasher md5 md5_context
mkIncrementalVerifier :: HashAlgorithm h => Context h -> Key -> IO IncrementalVerifier
mkIncrementalVerifier ctx key = do
v <- newMVar ctx
v <- newIORef ctx
return $ IncrementalVerifier
{ updateIncremental = \b -> do
ctx' <- takeMVar v
let ctx'' = hashUpdate ctx' b
evaluate $ rnf ctx''
putMVar v ctx''
{ updateIncremental = modifyIORef' v . flip hashUpdate
, finalizeIncremental = do
ctx' <- takeMVar v
ctx' <- readIORef v
let digest = hashFinalize ctx'
return $ sameCheckSum key (show digest)
}