@@ -44,7 +44,13 @@ import Handle.Common
4444
4545#ifdef INSPECTION
4646import Foreign.Storable (Storable)
47−import Streamly.Internal.Data.Stream.StreamD.Type (Step(..), GroupState)
47+import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
48+
49+import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
50+import qualified Streamly.Internal.Data.Strict as Strict
51+import qualified Streamly.Internal.Memory.Array as A
52+import qualified Streamly.Internal.Memory.Array.Types as AT
53+
4854import Test.Inspection
4955#endif
5056
@@ -52,25 +58,13 @@ import Test.Inspection
5258-- copy chunked
5359-------------------------------------------------------------------------------
5460
55−-- | Send the file contents to /dev/null
56−toChunksWithBufferOf :: Handle -> Handle -> IO ()
57−toChunksWithBufferOf inh devNull =
58− S.fold (IFH.writeChunks devNull) $ IFH.toChunksWithBufferOf (256*1024) inh
59−
60−#ifdef INSPECTION
61−inspect $ hasNoTypeClasses 'toChunksWithBufferOf
62−inspect $ 'toChunksWithBufferOf `hasNoType` ''Step
63−#endif
64−
6561-- | Copy file
6662copyChunks :: Handle -> Handle -> IO ()
67−copyChunks inh outh =
68− let s = IFH.toChunks inh
69− in S.fold (IFH.writeChunks outh) s
63+copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.toChunks inh
7064
7165#ifdef INSPECTION
72−inspect $ hasNoTypeClasses 'toChunksWriteChunks
73−inspect $ 'toChunksWriteChunks `hasNoType` ''Step
66+inspect $ hasNoTypeClasses 'copyChunks
67+inspect $ 'copyChunks `hasNoType` ''Step
7468#endif
7569
7670-- | Copy file
@@ -79,20 +73,18 @@ copyCodecUtf8ArraysLenient inh outh =
7973 S.fold (FH.write outh)
8074 $ SS.encodeUtf8
8175 $ IUS.decodeUtf8ArraysLenient
82− $ IFH.toChunksWithBufferOf (1024*1024) inh
76+ $ IFH.toChunks inh
8377
8478#ifdef INSPECTION
8579inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
8680-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''Step
87−-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''AT.FlattenState
88−-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''D.ConcatMapUState
8981#endif
9082
9183o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
9284o_1_space_copy_chunked env =
9385 [ bgroup "copy/toChunks"
94− [ mkBench "toNull (256K)" env $ \inH _ ->
95− toChunksWithBufferOf inH (nullH env)
86+ [ mkBench "toNull" env $ \inH _ ->
87+ copyChunks inH (nullH env)
9688 , mkBench "raw" env $ \inH outH ->
9789 copyChunks inH outH
9890 , mkBenchSmall "decodeEncodeUtf8Lenient" env $ \inH outH ->
@@ -107,44 +99,41 @@ o_1_space_copy_chunked env =
10799-------------------------------------------------------------------------------
108100
109101-- | Send the file contents to /dev/null with exception handling
110−readChunksWithBufferOfOnExceptionUnfold :: Handle -> Handle -> IO ()
111−readChunksWithBufferOfOnExceptionUnfold inh devNull =
112− let readEx = IUF.onException (\_ -> hClose inh)
113− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
102+readChunksOnException :: Handle -> Handle -> IO ()
103+readChunksOnException inh devNull =
104+ let readEx = IUF.onException (\_ -> hClose inh) FH.readChunks
114105 in IUF.fold readEx (IFH.writeChunks devNull) inh
115106
116107#ifdef INSPECTION
117−inspect $ hasNoTypeClasses 'readChunksWithBufferOfOnExceptionUnfold
118−-- inspect $ 'readChunksWithBufferOfOnExceptionUnfold `hasNoType` ''Step
108+inspect $ hasNoTypeClasses 'readChunksOnException
109+-- inspect $ 'readChunksOnException `hasNoType` ''Step
119110#endif
120111
121112-- | Send the file contents to /dev/null with exception handling
122−readChunksWithBufferOfBracketUnfold :: Handle -> Handle -> IO ()
123−readChunksWithBufferOfBracketUnfold inh devNull =
124− let readEx = IUF.bracket return (\_ -> hClose inh)
125− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
113+readChunksBracket :: Handle -> Handle -> IO ()
114+readChunksBracket inh devNull =
115+ let readEx = IUF.bracket return (\_ -> hClose inh) FH.readChunks
126116 in IUF.fold readEx (IFH.writeChunks devNull) inh
127117
128118#ifdef INSPECTION
129−inspect $ hasNoTypeClasses 'readChunksWithBufferOfBracketUnfold
130−-- inspect $ 'readChunksWithBufferOfBracketUnfold `hasNoType` ''Step
119+inspect $ hasNoTypeClasses 'readChunksBracket
120+-- inspect $ 'readChunksBracket `hasNoType` ''Step
131121#endif
132122
133−readChunksWithBufferOfBracketIOUnfold :: Handle -> Handle -> IO ()
134−readChunksWithBufferOfBracketIOUnfold inh devNull =
135− let readEx = IUF.bracketIO return (\_ -> hClose inh)
136− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
123+readChunksBracketIO :: Handle -> Handle -> IO ()
124+readChunksBracketIO inh devNull =
125+ let readEx = IUF.bracketIO return (\_ -> hClose inh) FH.readChunks
137126 in IUF.fold readEx (IFH.writeChunks devNull) inh
138127
139128o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
140129o_1_space_copy_exceptions_readChunks env =
141− [ bgroup "copy/exceptions/unfold/readChunks"
142− [ mkBench "onException (256K)" env $ \inH _ ->
143− readChunksWithBufferOfOnExceptionUnfold inH (nullH env)
144− , mkBench "bracket (256K)" env $ \inH _ ->
145− readChunksWithBufferOfBracketUnfold inH (nullH env)
146− , mkBench "bracketIO (256K)" env $ \inH _ ->
147− readChunksWithBufferOfBracketIOUnfold inH (nullH env)
130+ [ bgroup "copy/readChunks/exceptions"
131+ [ mkBench "UF.onException" env $ \inH _ ->
132+ readChunksOnException inH (nullH env)
133+ , mkBench "UF.bracket" env $ \inH _ ->
134+ readChunksBracket inH (nullH env)
135+ , mkBench "UF.bracketIO" env $ \inH _ ->
136+ readChunksBracketIO inH (nullH env)
148137 ]
149138 ]
150139
@@ -153,30 +142,34 @@ o_1_space_copy_exceptions_readChunks env =
153142-------------------------------------------------------------------------------
154143
155144-- | Send the file contents to /dev/null with exception handling
156−toChunksWithBufferOfBracketStream :: Handle -> Handle -> IO ()
157−toChunksWithBufferOfBracketStream inh devNull =
158− let readEx = S.bracket (return ()) (\_ -> hClose inh)
159− (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
145+toChunksBracket :: Handle -> Handle -> IO ()
146+toChunksBracket inh devNull =
147+ let readEx = S.bracket
148+ (return ())
149+ (\_ -> hClose inh)
150+ (\_ -> IFH.toChunks inh)
160151 in S.fold (IFH.writeChunks devNull) $ readEx
161152
162153#ifdef INSPECTION
163−inspect $ hasNoTypeClasses 'toChunksWithBufferOfBracketStream
164−-- inspect $ 'toChunksWithBufferOfBracketStream `hasNoType` ''Step
154+inspect $ hasNoTypeClasses 'toChunksBracket
155+-- inspect $ 'toChunksBracket `hasNoType` ''Step
165156#endif
166157
167−toChunksWithBufferOfBracketIOStream :: Handle -> Handle -> IO ()
168−toChunksWithBufferOfBracketIOStream inh devNull =
169− let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
170− (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
158+toChunksBracketIO :: Handle -> Handle -> IO ()
159+toChunksBracketIO inh devNull =
160+ let readEx = IP.bracketIO
161+ (return ())
162+ (\_ -> hClose inh)
163+ (\_ -> IFH.toChunks inh)
171164 in S.fold (IFH.writeChunks devNull) $ readEx
172165
173166o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
174167o_1_space_copy_exceptions_toChunks env =
175− [ bgroup "copy/exceptions/stream/toChunks"
176− [ mkBench "bracket (256K)" env $ \inH _ ->
177− toChunksWithBufferOfBracketStream inH (nullH env)
178− , mkBench "bracketIO (256K)" env $ \inH _ ->
179− toChunksWithBufferOfBracketIOStream inH (nullH env)
168+ [ bgroup "copy/toChunks/exceptions"
169+ [ mkBench "S.bracket" env $ \inH _ ->
170+ toChunksBracket inH (nullH env)
171+ , mkBench "S.bracketIO" env $ \inH _ ->
172+ toChunksBracketIO inH (nullH env)
180173 ]
181174 ]
182175
@@ -184,26 +177,17 @@ o_1_space_copy_exceptions_toChunks env =
184177-- copy unfold
185178-------------------------------------------------------------------------------
186179
187−-- | Send the file contents to /dev/null
188−readWriteNull :: Handle -> Handle -> IO ()
189−readWriteNull inh devNull = S.fold (FH.write devNull) $ S.unfold FH.read inh
190−
191−#ifdef INSPECTION
192−inspect $ hasNoTypeClasses 'readWriteNull
193−inspect $ 'readWriteNull `hasNoType` ''Step
194−inspect $ 'readWriteNull `hasNoType` ''AT.FlattenState
195−inspect $ 'readWriteNull `hasNoType` ''D.ConcatMapUState
196−#endif
197−
198180-- | Copy file
199181copyStream :: Handle -> Handle -> IO ()
200182copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.read inh)
201183
202184#ifdef INSPECTION
203185inspect $ hasNoTypeClasses 'copyStream
204−inspect $ 'copyStream `hasNoType` ''Step
205−inspect $ 'copyStream `hasNoType` ''AT.FlattenState
206−inspect $ 'copyStream `hasNoType` ''D.ConcatMapUState
186+inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
187+inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
188+inspect $ 'copyStream `hasNoType` ''A.ReadUState -- FH.read/A.read
189+inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
190+inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/lchunksOf
207191#endif
208192
209193-- | Copy file
@@ -217,8 +201,10 @@ copyStreamLatin1 inh outh =
217201#ifdef INSPECTION
218202inspect $ hasNoTypeClasses 'copyStreamLatin1
219203inspect $ 'copyStreamLatin1 `hasNoType` ''Step
220−inspect $ 'copyStreamLatin1 `hasNoType` ''AT.FlattenState
221−inspect $ 'copyStreamLatin1 `hasNoType` ''D.ConcatMapUState
204+inspect $ 'copyStreamLatin1 `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
205+inspect $ 'copyStreamLatin1 `hasNoType` ''A.ReadUState -- FH.read/A.read
206+inspect $ 'copyStreamLatin1 `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
207+inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- FH.write/lchunksOf
222208#endif
223209
224210-- | Copy file
@@ -255,7 +241,7 @@ o_1_space_copy_read :: BenchEnv -> [Benchmark]
255241o_1_space_copy_read env =
256242 [ bgroup "copy/read"
257243 [ mkBench "rawToNull" env $ \inh _ ->
258− readWriteNull inh (nullH env)
244+ copyStream inh (nullH env)
259245 , mkBench "rawToFile" env $ \inh outh ->
260246 copyStream inh outh
261247 -- This needs an ascii file, as decode just errors out.
@@ -279,10 +265,11 @@ readFromBytesNull :: Handle -> Handle -> IO ()
279265readFromBytesNull inh devNull = IFH.fromBytes devNull $ S.unfold FH.read inh
280266
281267#ifdef INSPECTION
282−inspect $ hasNoTypeClasses 'catStreamWrite
283−inspect $ 'catStreamWrite `hasNoType` ''Step
284−inspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
285−inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
268+inspect $ hasNoTypeClasses 'readFromBytesNull
269+inspect $ 'readFromBytesNull `hasNoType` ''Step
270+inspect $ 'readFromBytesNull `hasNoType` ''AT.SpliceState
271+inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
272+inspect $ 'readFromBytesNull `hasNoType` ''D.GroupState
286273#endif
287274
288275o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
@@ -306,8 +293,6 @@ readWriteOnExceptionUnfold inh devNull =
306293#ifdef INSPECTION
307294inspect $ hasNoTypeClasses 'readWriteOnExceptionUnfold
308295-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''Step
309−-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''AT.FlattenState
310−-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''D.ConcatMapUState
311296#endif
312297
313298-- | Send the file contents to /dev/null with exception handling
@@ -320,8 +305,6 @@ readWriteHandleExceptionUnfold inh devNull =
320305#ifdef INSPECTION
321306inspect $ hasNoTypeClasses 'readWriteHandleExceptionUnfold
322307-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''Step
323−-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''AT.FlattenState
324−-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''D.ConcatMapUState
325308#endif
326309
327310-- | Send the file contents to /dev/null with exception handling
@@ -333,8 +316,6 @@ readWriteFinallyUnfold inh devNull =
333316#ifdef INSPECTION
334317inspect $ hasNoTypeClasses 'readWriteFinallyUnfold
335318-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''Step
336−-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''AT.FlattenState
337−-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''D.ConcatMapUState
338319#endif
339320
340321readWriteFinallyIOUnfold :: Handle -> Handle -> IO ()
@@ -351,8 +332,6 @@ readWriteBracketUnfold inh devNull =
351332#ifdef INSPECTION
352333inspect $ hasNoTypeClasses 'readWriteBracketUnfold
353334-- inspect $ 'readWriteBracketUnfold `hasNoType` ''Step
354−-- inspect $ 'readWriteBracketUnfold `hasNoType` ''AT.FlattenState
355−-- inspect $ 'readWriteBracketUnfold `hasNoType` ''D.ConcatMapUState
356335#endif
357336
358337readWriteBracketIOUnfold :: Handle -> Handle -> IO ()
@@ -414,8 +393,8 @@ fromToBytesBracketStream inh devNull =
414393 in IFH.fromBytes devNull $ readEx
415394
416395#ifdef INSPECTION
417−inspect $ hasNoTypeClasses 'readWriteBracketStream
418−-- inspect $ 'readWriteBracketStream `hasNoType` ''Step
396+inspect $ hasNoTypeClasses 'fromToBytesBracketStream
397+-- inspect $ 'fromToBytesBracketStream `hasNoType` ''Step
419398#endif
420399
421400fromToBytesBracketIOStream :: Handle -> Handle -> IO ()
@@ -451,10 +430,10 @@ o_1_space_copy_stream_exceptions env =
451430-- | Lines and unlines
452431copyChunksSplitInterposeSuffix :: Handle -> Handle -> IO ()
453432copyChunksSplitInterposeSuffix inh outh =
454− S.fold (IFH.writeWithBufferOf (1024*1024) outh)
433+ S.fold (IFH.write outh)
455434 $ AS.interposeSuffix 10
456435 $ AS.splitOnSuffix 10
457− $ IFH.toChunksWithBufferOf (1024*1024) inh
436+ $ IFH.toChunks inh
458437
459438#ifdef INSPECTION
460439inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
@@ -464,11 +443,11 @@ inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
464443-- | Words and unwords
465444copyChunksSplitInterpose :: Handle -> Handle -> IO ()
466445copyChunksSplitInterpose inh outh =
467− S.fold (IFH.writeWithBufferOf (1024*1024) outh)
446+ S.fold (IFH.write outh)
468447 $ AS.interpose 32
469448 -- XXX this is not correct word splitting combinator
470449 $ AS.splitOn 32
471− $ IFH.toChunksWithBufferOf (1024*1024) inh
450+ $ IFH.toChunks inh
472451
473452#ifdef INSPECTION
474453inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
@@ -519,8 +498,6 @@ linesUnlinesArrayCharCopy inh outh =
519498#ifdef INSPECTION
520499inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Storable]
521500-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
522−-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''AT.FlattenState
523−-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''D.ConcatMapUState
524501#endif
525502
526503-- XXX to write this we need to be able to map decodeUtf8 on the A.read fold.
@@ -548,7 +525,6 @@ wordsUnwordsCopyWord8 inh outh =
548525#ifdef INSPECTION
549526inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
550527-- inspect $ 'wordsUnwordsCopyWord8 `hasNoType` ''Step
551−-- inspect $ 'wordsUnwordsCopyWord8 `hasNoType` ''D.ConcatMapUState
552528#endif
553529
554530-- | Word, unwords and copy
@@ -572,8 +548,6 @@ wordsUnwordsCopy inh outh =
572548#ifdef INSPECTION
573549-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
574550-- inspect $ 'wordsUnwordsCopy `hasNoType` ''Step
575−-- inspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
576−-- inspect $ 'wordsUnwordsCopy `hasNoType` ''D.ConcatMapUState
577551#endif
578552
579553wordsUnwordsCharArrayCopy :: Handle -> Handle -> IO ()