@@ -1065,26 +1065,32 @@ toLazyByteStringWith strategy k b =
1065
1065
-- 'Buffer's allocated according to the given 'AllocationStrategy'.
1066
1066
{-# INLINE buildStepToCIOS #-}
1067
1067
buildStepToCIOS
1068
- :: AllocationStrategy -- ^ Buffer allocation strategy to use
1068
+ :: forall a .
1069
+ AllocationStrategy -- ^ Buffer allocation strategy to use
1069
1070
-> BuildStep a -- ^ 'BuildStep' to execute
1070
1071
-> IO (ChunkIOStream a )
1071
1072
buildStepToCIOS (AllocationStrategy nextBuffer bufSize trim) =
1072
1073
\ step -> nextBuffer Nothing >>= fill step
1073
1074
where
1075
+ fill :: BuildStep a -> Buffer -> IO (ChunkIOStream a )
1074
1076
fill ! step buf@ (Buffer fpbuf br@ (BufferRange _ pe)) = do
1075
1077
res <- fillWithBuildStep step doneH fullH insertChunkH br
1076
1078
touchForeignPtr fpbuf
1077
1079
return res
1078
1080
where
1081
+ pbuf :: Ptr Word8
1079
1082
pbuf = unsafeForeignPtrToPtr fpbuf
1080
1083
1084
+ doneH :: Ptr Word8 -> a -> IO (ChunkIOStream a )
1081
1085
doneH op' x = return $
1082
1086
Finished (Buffer fpbuf (BufferRange op' pe)) x
1083
1087
1088
+ fullH :: Ptr Word8 -> Int -> BuildStep a -> IO (ChunkIOStream a )
1084
1089
fullH op' minSize nextStep =
1085
1090
wrapChunk op' $ const $
1086
1091
nextBuffer (Just (buf, max minSize bufSize)) >>= fill nextStep
1087
1092
1093
+ insertChunkH :: Ptr Word8 -> S. ByteString -> BuildStep a -> IO (ChunkIOStream a )
1088
1094
insertChunkH op' bs nextStep =
1089
1095
wrapChunk op' $ \ isEmpty -> yield1 bs $
1090
1096
-- Checking for empty case avoids allocating 'n-1' empty
@@ -1096,6 +1102,7 @@ buildStepToCIOS (AllocationStrategy nextBuffer bufSize trim) =
1096
1102
1097
1103
-- Wrap and yield a chunk, trimming it if necesary
1098
1104
{-# INLINE wrapChunk #-}
1105
+ wrapChunk :: Ptr Word8 -> (Bool -> IO (ChunkIOStream a )) -> IO (ChunkIOStream a )
1099
1106
wrapChunk ! op' mkCIOS
1100
1107
| chunkSize == 0 = mkCIOS True
1101
1108
| trim chunkSize size = do
0 commit comments