From b996afcd1f77c1ff902124ccb244b56b54899362 Mon Sep 17 00:00:00 2001 From: Adam Gundry Date: Wed, 24 May 2023 13:49:40 +0100 Subject: [PATCH] WIP: experimentally use dupIO to fix #318 This calls dupIO on the token stream each time the buffer is full. --- cborg/cborg.cabal | 1 + cborg/src/Codec/CBOR/Write.hs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cborg/cborg.cabal b/cborg/cborg.cabal index 32fd8ef..38a4bcf 100644 --- a/cborg/cborg.cabal +++ b/cborg/cborg.cabal @@ -94,6 +94,7 @@ library bytestring >= 0.10.4 && < 0.12, containers >= 0.5 && < 0.7, deepseq >= 1.0 && < 1.5, + dupIO, ghc-prim >= 0.3.1.0 && < 0.11, half >= 0.2.2.3 && < 0.4, primitive >= 0.5 && < 0.9, diff --git a/cborg/src/Codec/CBOR/Write.hs b/cborg/src/Codec/CBOR/Write.hs index 977685e..cd61715 100644 --- a/cborg/src/Codec/CBOR/Write.hs +++ b/cborg/src/Codec/CBOR/Write.hs @@ -75,6 +75,8 @@ import qualified Codec.CBOR.ByteArray.Sliced as BAS import Codec.CBOR.Encoding import Codec.CBOR.Magic +import qualified Data.Dup as Dup + -------------------------------------------------------------------------------- -- | Turn an 'Encoding' into a lazy 'L.ByteString' in CBOR binary @@ -194,7 +196,8 @@ buildStep vs1 k (BI.BufferRange op0 ope0) = TkEnd -> k (BI.BufferRange op ope0) - | otherwise = return $ BI.bufferFull bound op (buildStep vs k) + | otherwise = do vs' <- Dup.dupIO vs + return $ BI.bufferFull bound op (buildStep vs' k) -- The maximum size in bytes of the fixed-size encodings bound :: Int