on master help sign in
rename parseChunks to splitParse
commitf1eb9a18c2fbd0d622ab34960c9406d4d32f9271 authorHarendra Kumar <harendra@composewell.com> dateWed 25 Mar 2020, 01:14 (7 years ago) parent341a42a
6 files changed+37−37
benchmark/FileIO.hs+6−6 benchmark/Streamly/Benchmark/FileIO/Stream.hs+11−11 src/Streamly/Internal/Data/Fold.hs+1−1 src/Streamly/Internal/Data/Parser.hs+6−6 src/Streamly/Internal/Data/Stream/StreamD.hs+5−5 src/Streamly/Internal/Prelude.hs+8−8
benchmark/FileIO.hs+6−6
@@ -212,12 +212,12 @@ main = do
212212 , mkBench "sumChunksOf 1" href $ do
213213 Handles inh _ <- readIORef href
214214 BFS.chunksOfSum 1 inh
215− , mkBench "sumChunksOf (single chunk) (parseChunks)" href $ do
215+ , mkBench "sumChunksOf (single chunk) (splitParse)" href $ do
216216 Handles inh _ <- readIORef href
217− BFS.parseChunksOfSum fileSize inh
218− , mkBench "sumChunksOf 1 (parseChunks)" href $ do
217+ BFS.splitParseChunksOfSum fileSize inh
218+ , mkBench "sumChunksOf 1 (splitParse)" href $ do
219219 Handles inh _ <- readIORef href
220− BFS.parseChunksOfSum 1 inh
220+ BFS.splitParseChunksOfSum 1 inh
221221
222222 , mkBench "arraysOf 1" href $ do
223223 Handles inh _ <- readIORef href
@@ -268,9 +268,9 @@ main = do
268268 , mkBench "splitOnSuffix \\n (line count)" href $ do
269269 Handles inh _ <- readIORef href
270270 BFS.splitOnSuffix inh
271− , mkBench "splitOn \\n (line count) (parseChunks)" href $ do
271+ , mkBench "splitOn \\n (line count) (splitParse)" href $ do
272272 Handles inh _ <- readIORef href
273− BFS.parseChunksSplitOn inh
273+ BFS.splitParseSepBy inh
274274 , mkBench "wordsBy isSpace (word count)" href $ do
275275 Handles inh _ <- readIORef href
276276 BFS.wordsBy inh
benchmark/Streamly/Benchmark/FileIO/Stream.hs+11−11
@@ -57,12 +57,12 @@ module Streamly.Benchmark.FileIO.Stream
5757 , decodeUtf8Lax
5858 , copyCodecUtf8Lenient
5959 , chunksOfSum
60− , parseChunksOfSum
60+ , splitParseChunksOfSum
6161 , chunksOf
6262 , chunksOfD
6363 , splitOn
6464 , splitOnSuffix
65− , parseChunksSplitOn
65+ , splitParseSepBy
6666 , wordsBy
6767 , splitOnSeq
6868 , splitOnSeqUtf8
@@ -445,10 +445,10 @@ inspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
445445inspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
446446#endif
447447
448−{-# INLINE parseChunksOfSum #-}
449−parseChunksOfSum :: Int -> Handle -> IO Int
450−parseChunksOfSum n inh =
451− S.length $ IP.parseChunks (IFL.take n FL.sum) (S.unfold FH.read inh)
448+{-# INLINE splitParseChunksOfSum #-}
449+splitParseChunksOfSum :: Int -> Handle -> IO Int
450+splitParseChunksOfSum n inh =
451+ S.length $ IP.splitParse (IFL.take n FL.sum) (S.unfold FH.read inh)
452452
453453{-# INLINE linesUnlinesCopy #-}
454454linesUnlinesCopy :: Handle -> Handle -> IO ()
@@ -609,11 +609,11 @@ inspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
609609#endif
610610
611611-- | Split on line feed.
612−{-# INLINE parseChunksSplitOn #-}
613−parseChunksSplitOn :: Handle -> IO Int
614−parseChunksSplitOn inh =
615− (S.length $ IP.parseChunks (PR.sepBy (== lf) FL.drain)
616− (S.unfold FH.read inh)) -- >>= print
612+{-# INLINE splitParseSepBy #-}
613+splitParseSepBy :: Handle -> IO Int
614+splitParseSepBy inh =
615+ (S.length $ IP.splitParse (PR.sepBy (== lf) FL.drain)
616+ (S.unfold FH.read inh)) -- >>= print
617617
618618-- | Words by space
619619{-# INLINE wordsBy #-}
src/Streamly/Internal/Data/Fold.hs+1−1
@@ -838,7 +838,7 @@ or = Fold (\x a -> return $ x || a) (return False) return
838838-- Stops after @n@ elements.
839839-- Never fails.
840840--
841−-- S.chunksOf n f = S.parseChunks (FL.take n f)
841+-- S.chunksOf n f = S.splitParse (FL.take n f)
842842--
843843-- /Internal/
844844--
src/Streamly/Internal/Data/Parser.hs+6−6
@@ -227,10 +227,10 @@ takeWhile predicate (Fold fstep finitial fextract) =
227227-- >>> S.parse (PR.sepBy (== 1) FL.toList) $ S.fromList [0,0,1,0,1]
228228-- > Right [0,0]
229229--
230−-- >>> S.toList $ S.parseChunks (PR.sepBy (== 1) FL.toList) $ S.fromList [0,0,1,0,1]
230+-- >>> S.toList $ S.splitParse (PR.sepBy (== 1) FL.toList) $ S.fromList [0,0,1,0,1]
231231-- > [[0,0],[0],[]]
232232--
233−-- S.splitOn pred f = S.parseChunks (PR.sepBy pred f)
233+-- S.splitOn pred f = S.splitParse (PR.sepBy pred f)
234234--
235235-- /Internal/
236236--
@@ -256,7 +256,7 @@ sepBy predicate (Fold fstep finitial fextract) =
256256-- * Stops - when the predicate succeeds.
257257-- * Fails - never.
258258--
259−-- S.splitWithSuffix pred f = S.parseChunks (PR.sepWithSuffix pred f)
259+-- S.splitWithSuffix pred f = S.splitParse (PR.sepWithSuffix pred f)
260260--
261261-- /Unimplemented/
262262--
@@ -272,7 +272,7 @@ sepWithSuffix = undefined
272272-- * Stops - when the predicate succeeds.
273273-- * Fails - never.
274274--
275−-- S.splitWithPrefix pred f = S.parseChunks (PR.sepWithPrefix pred f)
275+-- S.splitWithPrefix pred f = S.splitParse (PR.sepWithPrefix pred f)
276276--
277277-- /Unimplemented/
278278--
@@ -316,7 +316,7 @@ sepByMax predicate count (Fold fstep finitial fextract) =
316316-- * Stops - when it finds a word separator after a non-word element
317317-- * Fails - never.
318318--
319−-- S.wordsBy pred f = S.parseChunks (PR.wordBy pred f)
319+-- S.wordsBy pred f = S.splitParse (PR.wordBy pred f)
320320--
321321-- /Unimplemented/
322322--
@@ -336,7 +336,7 @@ wordBy = undefined
336336-- * Stops - when the group ends.
337337-- * Fails - never.
338338--
339−-- S.groupsBy cmp f = S.parseChunks (PR.groupBy cmp f)
339+-- S.groupsBy cmp f = S.splitParse (PR.groupBy cmp f)
340340--
341341-- /Unimplemented/
342342--
src/Streamly/Internal/Data/Stream/StreamD.hs+5−5
@@ -129,7 +129,7 @@ module Streamly.Internal.Data.Stream.StreamD
129129 , runFold
130130
131131 , parselMx'
132− , parseChunks
132+ , splitParse
133133
134134 -- ** Specialized Folds
135135 , tap
@@ -953,7 +953,7 @@ foldlS fstep begin (Stream step state) = Stream step' (Left (state, begin))
953953------------------------------------------------------------------------------
954954
955955-- Inlined definition. Without the inline "serially/parser/take" benchmark
956−-- degrades and parseChunks does not fuse. Even using "inline" at the callsite
956+-- degrades and splitParse does not fuse. Even using "inline" at the callsite
957957-- does not help.
958958{-# INLINE splitAt #-}
959959splitAt :: Int -> [a] -> ([a],[a])
@@ -1034,13 +1034,13 @@ data ParseChunksState x inpBuf st pst =
10341034 | ParseChunksBuf inpBuf st inpBuf pst
10351035 | ParseChunksYield x (ParseChunksState x inpBuf st pst)
10361036
1037−{-# INLINE_NORMAL parseChunks #-}
1038−parseChunks
1037+{-# INLINE_NORMAL splitParse #-}
1038+splitParse
10391039 :: Monad m
10401040 => Parser m a b
10411041 -> Stream m a
10421042 -> Stream m b
1043−parseChunks (Parser pstep initial extract) (Stream step state) =
1043+splitParse (Parser pstep initial extract) (Stream step state) =
10441044 Stream stepOuter (ParseChunksInit [] state)
10451045
10461046 where
src/Streamly/Internal/Prelude.hs+8−8
@@ -267,7 +267,7 @@ module Streamly.Internal.Prelude
267267 , reverse'
268268
269269 -- ** Parsing
270− , parseChunks
270+ , splitParse
271271
272272 -- ** Trimming
273273 , take
@@ -3114,25 +3114,25 @@ concatMapTreeYieldLeavesWith combine f = concatMapLoopWith combine f yield
31143114------------------------------------------------------------------------------
31153115
31163116-- Splitting operations that take a predicate and a Fold can be
3117−-- expressed using parseChunks. Operations like chunksOf, intervalsOf, split*,
3118−-- can be expressed using parseChunks when used with an appropriate Parse.
3117+-- expressed using splitParse. Operations like chunksOf, intervalsOf, split*,
3118+-- can be expressed using splitParse when used with an appropriate Parse.
31193119--
31203120-- | Apply a 'Parse' repeatedly on a stream and emit the parsed values in the
31213121-- output stream.
31223122--
3123−-- >>> S.toList $ S.parseChunks (PR.take 2 $ PR.fromFold FL.sum) $ S.fromList [1..10]
3123+-- >>> S.toList $ S.splitParse (PR.take 2 $ PR.fromFold FL.sum) $ S.fromList [1..10]
31243124-- > [3,7,11,15,19]
31253125--
3126−-- >>> S.toList $ S.parseChunks (PR.line FL.toList) $ S.fromList "hello\nworld"
3126+-- >>> S.toList $ S.splitParse (PR.line FL.toList) $ S.fromList "hello\nworld"
31273127-- > ["hello\n","world"]
31283128--
3129−{-# INLINE parseChunks #-}
3130−parseChunks
3129+{-# INLINE splitParse #-}
3130+splitParse
31313131 :: (IsStream t, Monad m)
31323132 => Parser m a b
31333133 -> t m a
31343134 -> t m b
3135−parseChunks f m = D.fromStreamD $ D.parseChunks f (D.toStreamD m)
3135+splitParse f m = D.fromStreamD $ D.splitParse f (D.toStreamD m)
31363136
31373137------------------------------------------------------------------------------
31383138-- Grouping/Splitting