Skip to content

Commit 5ff777a

Browse files
Merge adaptC and adaptCG
1 parent b44ef16 commit 5ff777a

2 files changed

Lines changed: 48 additions & 38 deletions

File tree

core/src/Streamly/Internal/Data/Array.hs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,24 +1226,27 @@ adaptCWith pstep initial extract cont !offset0 !usedCount !input = do
12261226
-- The "n" here is stream position index wrt the array start, and
12271227
-- not the backtrack count as returned by byte stream parsers.
12281228
case pRes of
1229-
ParserD.Done 0 b ->
1229+
ParserD.SDone 1 b ->
12301230
onDone nextOff b
1231-
ParserD.Done 1 b ->
1231+
ParserD.SDone 0 b ->
12321232
onDone curOff b
1233-
ParserD.Done n b ->
1234-
onDone ((back n - start) `div` elemSize) b
1235-
ParserD.Partial 0 pst1 ->
1233+
ParserD.SDone m b ->
1234+
let n = 1 - m
1235+
in onDone ((back n - start) `div` elemSize) b
1236+
ParserD.SPartial 1 pst1 ->
12361237
go SPEC next pst1
1237-
ParserD.Partial 1 pst1 ->
1238+
ParserD.SPartial 0 pst1 ->
12381239
go SPEC cur pst1
1239-
ParserD.Partial n pst1 ->
1240-
onBack (back n) elemSize onPartial pst1
1241-
ParserD.Continue 0 pst1 ->
1240+
ParserD.SPartial m pst1 ->
1241+
let n = 1 - m
1242+
in onBack (back n) elemSize onPartial pst1
1243+
ParserD.SContinue 1 pst1 ->
12421244
go SPEC next pst1
1243-
ParserD.Continue 1 pst1 ->
1245+
ParserD.SContinue 0 pst1 ->
12441246
go SPEC cur pst1
1245-
ParserD.Continue n pst1 ->
1246-
onBack (back n) elemSize onContinue pst1
1247+
ParserD.SContinue m pst1 ->
1248+
let n = 1 - m
1249+
in onBack (back n) elemSize onContinue pst1
12471250
ParserD.Error err ->
12481251
onError curOff err
12491252

@@ -1254,17 +1257,19 @@ adaptCWith pstep initial extract cont !offset0 !usedCount !input = do
12541257
-- IMPORTANT: the n here is from the byte stream parser, that means
12551258
-- it is the backtrack element count and not the stream position
12561259
-- index into the current input array.
1257-
ParserD.Done n b ->
1258-
assert (n >= 0)
1259-
(cont (Success (- n) b) (count - n) None)
1260-
ParserD.Continue n pst1 ->
1261-
assert (n >= 0)
1262-
(return $ Continue (- n) (parseCont (count - n) pst1))
1260+
ParserD.SDone m b ->
1261+
let n = 1 - m
1262+
in assert (n >= 0)
1263+
(cont (Success (- n) b) (count - n) None)
1264+
ParserD.SContinue m pst1 ->
1265+
let n = 1 - m
1266+
in assert (n >= 0)
1267+
(return $ Continue (- n) (parseCont (count - n) pst1))
12631268
ParserD.Error err ->
12641269
-- XXX It is called only when there is no input arr. So using 0
12651270
-- as the position is correct?
12661271
cont (Failure 0 err) count None
1267-
ParserD.Partial _ _ -> error "Bug: adaptCWith Partial unreachable"
1272+
ParserD.SPartial _ _ -> error "Bug: adaptCWith Partial unreachable"
12681273

12691274
-- XXX Maybe we can use two separate continuations instead of using
12701275
-- Just/Nothing cases here. That may help in avoiding the parseContJust

core/src/Streamly/Internal/Data/Array/Generic.hs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -603,24 +603,27 @@ adaptCGWith pstep initial extract cont !offset0 !usedCount !input = do
603603
-- The "n" here is stream position index wrt the array start, and
604604
-- not the backtrack count as returned by byte stream parsers.
605605
case pRes of
606-
ParserD.Done 0 b ->
606+
ParserD.SDone 1 b ->
607607
onDone nextOff b
608-
ParserD.Done 1 b ->
608+
ParserD.SDone 0 b ->
609609
onDone curOff b
610-
ParserD.Done n b ->
611-
onDone (back n - start) b
612-
ParserD.Partial 0 pst1 ->
610+
ParserD.SDone m b ->
611+
let n = 1 - m
612+
in onDone (back n - start) b
613+
ParserD.SPartial 1 pst1 ->
613614
go SPEC next pst1
614-
ParserD.Partial 1 pst1 ->
615+
ParserD.SPartial 0 pst1 ->
615616
go SPEC cur pst1
616-
ParserD.Partial n pst1 ->
617-
onBack (back n) onPartial pst1
618-
ParserD.Continue 0 pst1 ->
617+
ParserD.SPartial m pst1 ->
618+
let n = 1 - m
619+
in onBack (back n) onPartial pst1
620+
ParserD.SContinue 1 pst1 ->
619621
go SPEC next pst1
620-
ParserD.Continue 1 pst1 ->
622+
ParserD.SContinue 0 pst1 ->
621623
go SPEC cur pst1
622-
ParserD.Continue n pst1 ->
623-
onBack (back n) onContinue pst1
624+
ParserD.SContinue m pst1 ->
625+
let n = 1 - m
626+
in onBack (back n) onContinue pst1
624627
ParserD.Error err ->
625628
onError curOff err
626629

@@ -631,17 +634,19 @@ adaptCGWith pstep initial extract cont !offset0 !usedCount !input = do
631634
-- IMPORTANT: the n here is from the byte stream parser, that means
632635
-- it is the backtrack element count and not the stream position
633636
-- index into the current input array.
634-
ParserD.Done n b ->
635-
assert (n >= 0)
636-
(cont (Success (- n) b) (count - n) None)
637-
ParserD.Continue n pst1 ->
638-
assert (n >= 0)
639-
(return $ Continue (- n) (parseCont (count - n) pst1))
637+
ParserD.SDone m b ->
638+
let n = 1 - m
639+
in assert (n >= 0)
640+
(cont (Success (- n) b) (count - n) None)
641+
ParserD.SContinue m pst1 ->
642+
let n = 1 - m
643+
in assert (n >= 0)
644+
(return $ Continue (- n) (parseCont (count - n) pst1))
640645
ParserD.Error err ->
641646
-- XXX It is called only when there is no input arr. So using 0
642647
-- as the position is correct?
643648
cont (Failure 0 err) count None
644-
ParserD.Partial _ _ -> error "Bug: adaptCGWith Partial unreachable"
649+
ParserD.SPartial _ _ -> error "Bug: adaptCGWith Partial unreachable"
645650

646651
{-# INLINE parseCont #-}
647652
parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr

0 commit comments

Comments
 (0)