@@ -245,9 +245,9 @@ data SlowPath s a
245245#else
246246 | SlowPeekByteOffset {-# UNPACK #-} ! ByteString (Int # -> ST s (DecodeAction s a))
247247#endif
248- | SlowMarkInput {-# UNPACK #-} ! ByteString (ST s (DecodeAction s a))
249- | SlowUnmarkInput {-# UNPACK #-} ! ByteString (ST s (DecodeAction s a))
250- | SlowGetInputSpan {-# UNPACK #-} ! ByteString (LBS. ByteString -> ST s (DecodeAction s a))
248+ | SlowOpenByteSpan {-# UNPACK #-} ! ByteString (ST s (DecodeAction s a))
249+ | SlowCloseByteSpan {-# UNPACK #-} ! ByteString (ST s (DecodeAction s a))
250+ | SlowPeekByteSpan {-# UNPACK #-} ! ByteString (LBS. ByteString -> ST s (DecodeAction s a))
251251 | SlowDecodeAction {-# UNPACK #-} ! ByteString (DecodeAction s a)
252252 | SlowFail {-# UNPACK #-} ! ByteString String
253253
@@ -704,9 +704,9 @@ go_fast !bs (PeekTokenType k) =
704704go_fast ! bs (PeekAvailable k) = k (case BS. length bs of I # len# -> len# ) >>= go_fast bs
705705
706706go_fast ! bs da@ PeekByteOffset {} = go_fast_end bs da
707- go_fast ! bs da@ MarkInput {} = go_fast_end bs da
708- go_fast ! bs da@ UnmarkInput {} = go_fast_end bs da
709- go_fast ! bs da@ GetInputSpan {} = go_fast_end bs da
707+ go_fast ! bs da@ OpenByteSpan {} = go_fast_end bs da
708+ go_fast ! bs da@ CloseByteSpan {} = go_fast_end bs da
709+ go_fast ! bs da@ PeekByteSpan {} = go_fast_end bs da
710710go_fast ! bs da@ D. Fail {} = go_fast_end bs da
711711go_fast ! bs da@ D. Done {} = go_fast_end bs da
712712
@@ -727,9 +727,9 @@ go_fast_end !bs (D.Done x) = return $! FastDone bs x
727727go_fast_end ! bs (PeekAvailable k) = k (case BS. length bs of I # len# -> len# ) >>= go_fast_end bs
728728
729729go_fast_end ! bs (PeekByteOffset k) = return $! SlowPeekByteOffset bs k
730- go_fast_end ! bs (MarkInput k) = return $! SlowMarkInput bs k
731- go_fast_end ! bs (UnmarkInput k) = return $! SlowUnmarkInput bs k
732- go_fast_end ! bs (GetInputSpan k) = return $! SlowGetInputSpan bs k
730+ go_fast_end ! bs (OpenByteSpan k) = return $! SlowOpenByteSpan bs k
731+ go_fast_end ! bs (CloseByteSpan k) = return $! SlowCloseByteSpan bs k
732+ go_fast_end ! bs (PeekByteSpan k) = return $! SlowPeekByteSpan bs k
733733
734734-- the next two cases only need the 1 byte token header
735735go_fast_end ! bs da | BS. null bs = return $! SlowDecodeAction bs da
@@ -1207,8 +1207,12 @@ go_fast_end !bs (ConsumeMapLenOrIndef k) =
12071207 DecodedToken sz (I # n# ) -> k n# >>= go_fast_end (BS. unsafeDrop sz bs)
12081208
12091209
1210- -- Marks is a record of byteoffsets for input marks as well as input chunks seen since the first mark.
1211- -- The structure is a stack to support nesting marks / getInputSpan
1210+ -- | 'Marks' is a record of 'ByteOffsets' for input byte span marks, as well as
1211+ -- input chunks seen since the first mark.
1212+ --
1213+ -- The structure is a stack to support nesting of 'OpenByteSpan' and
1214+ -- 'CloseByteSpan'.
1215+ --
12121216data Marks
12131217 = NoMarks
12141218 | Marks ! ByteOffsets ! Chunks
@@ -1230,39 +1234,39 @@ data Chunks
12301234 | C_Cons ! ByteOffset ! ByteString ! Chunks
12311235 deriving Show
12321236
1233- slowMarkInput :: ByteString -> ByteOffset -> Marks -> Marks
1234- slowMarkInput bs off NoMarks = Marks (BO_Last off) (C_Cons off bs C_Nil )
1235- slowMarkInput _ off (Marks offs chunks) = Marks (BO_Cons off offs) chunks
1237+ markByteSpan :: ByteString -> ByteOffset -> Marks -> Marks
1238+ markByteSpan bs off NoMarks = Marks (BO_Last off) (C_Cons off bs C_Nil )
1239+ markByteSpan _ off (Marks offs chunks) = Marks (BO_Cons off offs) chunks
12361240
1237- slowUnmarkInput :: Marks -> Marks
1238- slowUnmarkInput NoMarks = NoMarks
1239- slowUnmarkInput (Marks (BO_Last _) _) = NoMarks
1240- slowUnmarkInput (Marks (BO_Cons _ offs) chunks) = Marks offs chunks
1241+ unmarkByteSpan :: Marks -> Marks
1242+ unmarkByteSpan NoMarks = NoMarks
1243+ unmarkByteSpan (Marks (BO_Last _) _) = NoMarks
1244+ unmarkByteSpan (Marks (BO_Cons _ offs) chunks) = Marks offs chunks
12411245
1242- slowMarkChunk :: ByteString -> ByteOffset -> Marks -> Marks
1243- slowMarkChunk _ _ NoMarks = NoMarks
1244- slowMarkChunk bs off (Marks offs chunks) = Marks offs (C_Cons off bs chunks)
1246+ markChunk :: ByteString -> ByteOffset -> Marks -> Marks
1247+ markChunk _ _ NoMarks = NoMarks
1248+ markChunk bs off (Marks offs chunks) = Marks offs (C_Cons off bs chunks)
12451249
1246- slowGetInputSpan :: ByteOffset -> Marks -> LBS. ByteString
1247- slowGetInputSpan _ NoMarks = LBS. empty
1248- slowGetInputSpan ! offset (Marks offs chunks) =
1250+ peekMarkedByteSpan :: ByteOffset -> Marks -> LBS. ByteString
1251+ peekMarkedByteSpan _ NoMarks = LBS. empty
1252+ peekMarkedByteSpan ! offset (Marks offs chunks) =
12491253 -- traceShow (off, offset, chunks) $ traceShowId $
1250- slowGetInputSpan1 (headByteOffsets offs) offset chunks
1254+ peekMarkedByteSpan1 (headByteOffsets offs) offset chunks
12511255
1252- slowGetInputSpan1 :: ByteOffset -> ByteOffset -> Chunks -> LBS. ByteString
1253- slowGetInputSpan1 ! _ ! _ C_Nil = LBS. empty
1254- slowGetInputSpan1 ! a ! b (C_Cons c bs chunks) =
1256+ peekMarkedByteSpan1 :: ByteOffset -> ByteOffset -> Chunks -> LBS. ByteString
1257+ peekMarkedByteSpan1 ! _ ! _ C_Nil = LBS. empty
1258+ peekMarkedByteSpan1 ! a ! b (C_Cons c bs chunks) =
12551259 assert (b >= c) $
12561260 if a <= c
12571261 -- a <= b, a <= c: take a prefix of the current chunk, recurse
1258- then slowGetInputSpan2 [BS. take (int64ToInt (b - c)) bs] a chunks
1262+ then peekMarkedByteSpan2 [BS. take (int64ToInt (b - c)) bs] a chunks
12591263 -- c < a <= b: the input span is completely inside the current chunk.
12601264 else LBS. fromStrict $ BS. take (int64ToInt (b - a)) $ BS. drop (int64ToInt (a - c)) bs
12611265
1262- slowGetInputSpan2 :: [ByteString ] -> ByteOffset -> Chunks -> LBS. ByteString
1263- slowGetInputSpan2 bss ! _ C_Nil = LBS. fromChunks bss
1264- slowGetInputSpan2 bss ! a (C_Cons c bs chunks)
1265- | a < c = slowGetInputSpan2 (bs : bss) a chunks
1266+ peekMarkedByteSpan2 :: [ByteString ] -> ByteOffset -> Chunks -> LBS. ByteString
1267+ peekMarkedByteSpan2 bss ! _ C_Nil = LBS. fromChunks bss
1268+ peekMarkedByteSpan2 bss ! a (C_Cons c bs chunks)
1269+ | a < c = peekMarkedByteSpan2 (bs : bss) a chunks
12661270 | a == c = LBS. fromChunks (bs : bss)
12671271 | otherwise = LBS. fromChunks (BS. drop (int64ToInt (a - c)) bs : bss)
12681272
@@ -1318,7 +1322,7 @@ go_slow da bs !offset !marks = do
13181322 mbs <- needChunk
13191323 case mbs of
13201324 Nothing -> decodeFail bs' offset' " end of input"
1321- Just bs'' -> go_slow da' bs'' offset' (slowMarkChunk bs'' offset' marks)
1325+ Just bs'' -> go_slow da' bs'' offset' (markChunk bs'' offset' marks)
13221326 where
13231327 ! offset' = offset + intToInt64 (BS. length bs - BS. length bs')
13241328
@@ -1342,18 +1346,18 @@ go_slow da bs !offset !marks = do
13421346 where
13431347 ! offset'@ (I64 # off# ) = offset + intToInt64 (BS. length bs - BS. length bs')
13441348
1345- SlowMarkInput bs' k ->
1346- lift k >>= \ daz -> go_slow daz bs' offset' (slowMarkInput bs' offset' marks)
1349+ SlowOpenByteSpan bs' k ->
1350+ lift k >>= \ daz -> go_slow daz bs' offset' (markByteSpan bs' offset' marks)
13471351 where
13481352 ! offset' = offset + intToInt64 (BS. length bs - BS. length bs')
13491353
1350- SlowUnmarkInput bs' k ->
1351- lift k >>= \ daz -> go_slow daz bs' offset' (slowUnmarkInput marks)
1354+ SlowCloseByteSpan bs' k ->
1355+ lift k >>= \ daz -> go_slow daz bs' offset' (unmarkByteSpan marks)
13521356 where
13531357 ! offset' = offset + intToInt64 (BS. length bs - BS. length bs')
13541358
1355- SlowGetInputSpan bs' k ->
1356- lift (k (slowGetInputSpan offset' marks)) >>= \ daz -> go_slow daz bs' offset' marks
1359+ SlowPeekByteSpan bs' k ->
1360+ lift (k (peekMarkedByteSpan offset' marks)) >>= \ daz -> go_slow daz bs' offset' marks
13571361 where
13581362 ! offset' = offset + intToInt64 (BS. length bs - BS. length bs')
13591363
@@ -1384,7 +1388,7 @@ go_slow_fixup da !bs !offset !marks = do
13841388 | otherwise
13851389 -> go_slow_fixup da (bs <> bs') offset marks'
13861390 where
1387- marks' = slowMarkChunk bs' (offset + intToInt64 (BS. length bs)) marks
1391+ marks' = markChunk bs' (offset + intToInt64 (BS. length bs)) marks
13881392
13891393-- We've now got more input, but we have one token that spanned the old and
13901394-- new input buffers, so we have to decode that one before carrying on
@@ -1468,15 +1472,15 @@ go_slow_overlapped da sz bs_cur bs_next !offset !marks =
14681472 where
14691473 ! (I64 # off# ) = offset'
14701474
1471- SlowMarkInput bs_empty k ->
1475+ SlowOpenByteSpan bs_empty k ->
14721476 assert (BS. null bs_empty) $
1473- lift k >>= \ daz -> go_slow daz bs' offset' (slowMarkInput bs' offset' marks)
1474- SlowUnmarkInput bs_empty k ->
1477+ lift k >>= \ daz -> go_slow daz bs' offset' (markByteSpan bs' offset' marks)
1478+ SlowCloseByteSpan bs_empty k ->
14751479 assert (BS. null bs_empty) $
1476- lift k >>= \ daz -> go_slow daz bs' offset' (slowUnmarkInput marks)
1477- SlowGetInputSpan bs_empty k ->
1480+ lift k >>= \ daz -> go_slow daz bs' offset' (unmarkByteSpan marks)
1481+ SlowPeekByteSpan bs_empty k ->
14781482 assert (BS. null bs_empty) $
1479- lift (k (slowGetInputSpan offset' marks)) >>= \ daz -> go_slow daz bs' offset' marks
1483+ lift (k (peekMarkedByteSpan offset' marks)) >>= \ daz -> go_slow daz bs' offset' marks
14801484
14811485 SlowFail bs_unconsumed msg ->
14821486 decodeFail (bs_unconsumed <> bs') offset'' msg
@@ -1506,13 +1510,13 @@ getTokenVarLen len bs offset marks =
15061510 | let n = len - BS. length bs
15071511 , BS. length bs' >= n ->
15081512 let ! tok = bs <> BS. unsafeTake n bs'
1509- in return (tok, BS. drop n bs', slowMarkChunk bs' offset marks)
1513+ in return (tok, BS. drop n bs', markChunk bs' offset marks)
15101514
15111515 | otherwise -> getTokenVarLenSlow
15121516 [bs',bs]
15131517 (len - (BS. length bs + BS. length bs'))
15141518 (offset + intToInt64 (BS. length bs'))
1515- (slowMarkChunk bs' offset marks)
1519+ (markChunk bs' offset marks)
15161520
15171521getTokenVarLenSlow
15181522 :: [ByteString ] -- ^ prefix chunks, in reverse order
@@ -1527,7 +1531,7 @@ getTokenVarLenSlow bss n offset marks = do
15271531 Just bs
15281532 | BS. length bs >= n ->
15291533 let ! tok = BS. concat (reverse (BS. unsafeTake n bs : bss))
1530- in return (tok, BS. drop n bs, slowMarkChunk bs offset marks)
1534+ in return (tok, BS. drop n bs, markChunk bs offset marks)
15311535 | otherwise -> getTokenVarLenSlow (bs: bss) (n - BS. length bs) (offset + intToInt64 (BS. length bs)) marks
15321536
15331537
0 commit comments