@@ -56,7 +56,15 @@ import qualified Streamly.Internal.Data.Parser.ParserD.Type as ParserD
56-- Note: We cannot use an Array directly as input because we need to identify
56-- Note: We cannot use an Array directly as input because we need to identify
57-- the end of input case using None. We cannot do that using nil Array as nil
57-- the end of input case using None. We cannot do that using nil Array as nil
58-- Arrays can be encountered in normal input as well.
58-- Arrays can be encountered in normal input as well.
60+-- We could specialize the ParserK type to use an Array directly, that provides
61+-- some performance improvement. The best advantage of that is when we consume
62+-- one element at a time from the array. If we really want that perf
63+-- improvement we can use a special ParserK type with the following Input.
59−data Input a = None | Chunk {-# UNPACK #-} !(Array a)
65+-- data Input a = None | Chunk {-# UNPACK #-} !(Array a)
67+data Input a = None | Chunk a
61-- | The intermediate result of running a parser step. The parser driver may
69-- | The intermediate result of running a parser step. The parser driver may
62-- stop with a final result, pause with a continuation to resume, or fail with
70-- stop with a final result, pause with a continuation to resume, or fail with
@@ -72,9 +80,6 @@ data Step a m r =
72 -- The Int is the current stream position index wrt to the start of the
80 -- The Int is the current stream position index wrt to the start of the
74 Done !Int r
82 Done !Int r
75− -- XXX we can use a "resume" and a "stop" continuations instead of Maybe.
76− -- measure if that works any better.
77− -- Array a -> m (Step a m r), m (Step a m r)
78 | Partial !Int (Input a -> m (Step a m r))
83 | Partial !Int (Input a -> m (Step a m r))
79 | Continue !Int (Input a -> m (Step a m r))
84 | Continue !Int (Input a -> m (Step a m r))
80 | Error !Int String
85 | Error !Int String
@@ -371,11 +376,11 @@ parseDToK
371 => (s -> a -> m (ParserD.Step s b))
376 => (s -> a -> m (ParserD.Step s b))
372 -> m (ParserD.Initial s b)
377 -> m (ParserD.Initial s b)
373 -> (s -> m (ParserD.Step s b))
378 -> (s -> m (ParserD.Step s b))
374− -> (ParseResult b -> Int -> Input a -> m (Step a m r))
379+ -> (ParseResult b -> Int -> Input (Array a) -> m (Step (Array a) m r))
377− -> Input a
382+ -> Input (Array a)
378− -> m (Step a m r)
383+ -> m (Step (Array a) m r)
379parseDToK pstep initial extract cont !offset0 !usedCount !input = do
384parseDToK pstep initial extract cont !offset0 !usedCount !input = do
380 res <- initial
385 res <- initial
381 case res of
386 case res of
@@ -494,7 +499,7 @@ parseDToK pstep initial extract cont !offset0 !usedCount !input = do
494-- /Pre-release/
499-- /Pre-release/
496{-# INLINE_LATE fromParser #-}
501{-# INLINE_LATE fromParser #-}
497−fromParser :: (Monad m, Unbox a) => ParserD.Parser a m b -> ParserK a m b
502+fromParser :: (Monad m, Unbox a) => ParserD.Parser a m b -> ParserK (Array a) m b
498fromParser (ParserD.Parser step initial extract) =
503fromParser (ParserD.Parser step initial extract) =
499 MkParser $ parseDToK step initial extract
504 MkParser $ parseDToK step initial extract