Skip to content

Commit 1c2269e

Browse files
committed
Add SPECIALISE for the CRC32C module functions
1 parent 0cf251d commit 1c2269e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Database/LSMTree/Internal/CRC32C.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
-- * Support for verifying checksums of files.
1414
-- * Support for a text file format listing file checksums.
1515
--
16-
-- TODO: specialise all the functions here to IO
1716
module Database.LSMTree.Internal.CRC32C (
1817

1918
CRC32C(..),
@@ -80,7 +79,7 @@ initialCRC32C = CRC32C 0 -- same as crc32c BS.empty
8079
updateCRC32C :: BS.ByteString -> CRC32C -> CRC32C
8180
updateCRC32C bs (CRC32C crc) = CRC32C (CRC.crc32c_update crc bs)
8281

83-
82+
{-# SPECIALISE hGetSomeCRC32C :: HasFS IO h -> Handle h -> Word64 -> CRC32C -> IO (BS.ByteString, CRC32C) #-}
8483
hGetSomeCRC32C :: Monad m
8584
=> HasFS m h
8685
-> Handle h
@@ -101,6 +100,7 @@ hGetSomeCRC32C fs h n crc = do
101100
-- TODO: To reliably return a strict bytestring without additional copying,
102101
-- @fs-api@ needs to support directly reading into a buffer, which is currently
103102
-- work in progress: <https://github.com/input-output-hk/fs-sim/pull/46>
103+
{-# SPECIALISE hGetExactlyCRC32C :: HasFS IO h -> Handle h -> Word64 -> CRC32C -> IO (BSL.ByteString, CRC32C) #-}
104104
hGetExactlyCRC32C :: MonadThrow m
105105
=> HasFS m h
106106
-> Handle h
@@ -112,6 +112,7 @@ hGetExactlyCRC32C fs h n crc = do
112112
return (lbs, crc')
113113

114114

115+
{-# SPECIALISE hPutSomeCRC32C :: HasFS IO h -> Handle h -> BS.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
115116
hPutSomeCRC32C :: Monad m
116117
=> HasFS m h
117118
-> Handle h
@@ -124,6 +125,7 @@ hPutSomeCRC32C fs h bs crc = do
124125

125126

126127
-- | This function makes sure that the whole 'BS.ByteString' is written.
128+
{-# SPECIALISE hPutAllCRC32C :: HasFS IO h -> Handle h -> BS.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
127129
hPutAllCRC32C :: forall m h
128130
. Monad m
129131
=> HasFS m h
@@ -142,6 +144,7 @@ hPutAllCRC32C fs h = go 0
142144
else go written' bs' crc'
143145

144146
-- | This function makes sure that the whole /lazy/ 'BSL.ByteString' is written.
147+
{-# SPECIALISE hPutAllChunksCRC32C :: HasFS IO h -> Handle h -> BSL.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
145148
hPutAllChunksCRC32C :: forall m h
146149
. Monad m
147150
=> HasFS m h
@@ -156,6 +159,7 @@ hPutAllChunksCRC32C fs h = \lbs crc ->
156159
(n, crc') <- hPutAllCRC32C fs h bs crc
157160
return (written + n, crc')
158161

162+
{-# SPECIALISE readFileCRC32C :: HasFS IO h -> FsPath -> IO CRC32C #-}
159163
readFileCRC32C :: forall m h. MonadThrow m => HasFS m h -> FsPath -> m CRC32C
160164
readFileCRC32C fs file =
161165
withFile fs file ReadMode (\h -> go h initialCRC32C)
@@ -267,6 +271,7 @@ data ChecksumsFileFormatError = ChecksumsFileFormatError FsPath BSC.ByteString
267271

268272
instance Exception ChecksumsFileFormatError
269273

274+
{-# SPECIALISE readChecksumsFile :: HasFS IO h -> FsPath -> IO ChecksumsFile #-}
270275
readChecksumsFile :: MonadThrow m
271276
=> HasFS m h -> FsPath -> m ChecksumsFile
272277
readChecksumsFile fs path = do
@@ -275,13 +280,15 @@ readChecksumsFile fs path = do
275280
Left badline -> throwIO (ChecksumsFileFormatError path badline)
276281
Right checksums -> return checksums
277282

283+
{-# SPECIALISE writeChecksumsFile :: HasFS IO h -> FsPath -> ChecksumsFile -> IO () #-}
278284
writeChecksumsFile :: MonadThrow m
279285
=> HasFS m h -> FsPath -> ChecksumsFile -> m ()
280286
writeChecksumsFile fs path checksums =
281287
withFile fs path (WriteMode MustBeNew) $ \h -> do
282288
_ <- hPutAll fs h (formatChecksumsFile checksums)
283289
return ()
284290

291+
{-# SPECIALISE writeChecksumsFile' :: HasFS IO h -> Handle h -> ChecksumsFile -> IO () #-}
285292
writeChecksumsFile' :: MonadThrow m
286293
=> HasFS m h -> Handle h -> ChecksumsFile -> m ()
287294
writeChecksumsFile' fs h checksums = void $ hPutAll fs h (formatChecksumsFile checksums)

0 commit comments

Comments
 (0)