on master help sign in
Remove SPEC from parseCont
commitd33205f017cab9a73d01fb75d22a7f8e006d6430 authorHarendra Kumar <harendra@composewell.com> dateThu 16 Feb 2023, 10:51 (4 years ago) parent021ac26
1 file changed+9−5
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+9−5
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+9−5
@@ -110,6 +110,10 @@ instance Functor ParseResult where
110110--
111111newtype Parser a m b = MkParser
112112 { runParser :: forall r.
113+ -- Using "Input" in runParser is not necessary but it avoids making
114+ -- one more function call to get the input. This could be helpful
115+ -- for cases where we process just one element per call.
116+ --
113117 (ParseResult b -> Int -> Input a -> m (Step a m r))
114118 -- XXX Maintain and pass the original position in the stream. that
115119 -- way we can also report better errors. Use a Context structure for
@@ -453,10 +457,10 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
453457 (cont (Success n b) (count + n - off) (Chunk arr))
454458 ChunkPartial n pst1 ->
455459 assert (n < 0 || n >= Array.length arr)
456− (return $ Partial n (parseCont SPEC (count + n - off) pst1))
460+ (return $ Partial n (parseCont (count + n - off) pst1))
457461 ChunkContinue n pst1 ->
458462 assert (n < 0 || n >= Array.length arr)
459− (return $ Continue n (parseCont SPEC (count + n - off) pst1))
463+ (return $ Continue n (parseCont (count + n - off) pst1))
460464 ChunkError n err ->
461465 cont (Failure n err) (count + n - off) (Chunk arr)
462466
@@ -472,7 +476,7 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
472476 (cont (Success (- n) b) (count - n) None)
473477 ParserD.Continue n pst1 ->
474478 assert (n >= 0)
475− (return $ Continue (- n) (parseCont SPEC (count - n) pst1))
479+ (return $ Continue (- n) (parseCont (count - n) pst1))
476480 ParserD.Error err ->
477481 -- XXX It is called only when there is no input arr. So using 0
478482 -- as the position is correct?
@@ -483,8 +487,8 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
483487 -- Just/Nothing cases here. That may help in avoiding the parseContJust
484488 -- function call.
485489 {-# INLINE parseCont #-}
486− parseCont _ !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
487− parseCont _ !cnt !pst None = parseContNothing cnt pst
490+ parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
491+ parseCont !cnt !pst None = parseContNothing cnt pst
488492
489493-- | Convert a raw byte 'Parser' to a chunked 'ParserK'.
490494--