From 3141522ca8b5871b698b3b52136dac7e8022bbd9 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 before evaluating each token in the token stream. --- cborg/cborg.cabal | 1 + cborg/src/Codec/CBOR/Write.hs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cborg/cborg.cabal b/cborg/cborg.cabal index 16bcb1d..39a2a4e 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..20d3139 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 @@ -110,7 +112,9 @@ buildStep vs1 k (BI.BufferRange op0 ope0) = go vs1 op0 where go vs !op - | op `plusPtr` bound <= ope0 = case vs of + | op `plusPtr` bound <= ope0 = do + dup_vs <- Dup.dupIO vs + case dup_vs of TkWord x vs' -> PI.runB wordMP x op >>= go vs' TkWord64 x vs' -> PI.runB word64MP x op >>= go vs'