Skip to content

Commit b996afc

Browse files
committed
WIP: experimentally use dupIO to fix #318
This calls dupIO on the token stream each time the buffer is full.
1 parent ec399a1 commit b996afc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cborg/cborg.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ library
9494
bytestring >= 0.10.4 && < 0.12,
9595
containers >= 0.5 && < 0.7,
9696
deepseq >= 1.0 && < 1.5,
97+
dupIO,
9798
ghc-prim >= 0.3.1.0 && < 0.11,
9899
half >= 0.2.2.3 && < 0.4,
99100
primitive >= 0.5 && < 0.9,

cborg/src/Codec/CBOR/Write.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import qualified Codec.CBOR.ByteArray.Sliced as BAS
7575
import Codec.CBOR.Encoding
7676
import Codec.CBOR.Magic
7777

78+
import qualified Data.Dup as Dup
79+
7880
--------------------------------------------------------------------------------
7981

8082
-- | Turn an 'Encoding' into a lazy 'L.ByteString' in CBOR binary
@@ -194,7 +196,8 @@ buildStep vs1 k (BI.BufferRange op0 ope0) =
194196

195197
TkEnd -> k (BI.BufferRange op ope0)
196198

197-
| otherwise = return $ BI.bufferFull bound op (buildStep vs k)
199+
| otherwise = do vs' <- Dup.dupIO vs
200+
return $ BI.bufferFull bound op (buildStep vs' k)
198201

199202
-- The maximum size in bytes of the fixed-size encodings
200203
bound :: Int

0 commit comments

Comments
 (0)