Ticket #5601: 0001-Add-NFData-instances-for-strict-and-lazy-ByteStrings.patch

File 0001-Add-NFData-instances-for-strict-and-lazy-ByteStrings.patch, 2.6 KB (added by basvandijk, 2 years ago)
  • Data/ByteString/Internal.hs

    From f9852a947932477ca72a8328c24d65210e9f7384 Mon Sep 17 00:00:00 2001
    From: Bas van Dijk <v.dijk.bas@gmail.com>
    Date: Wed, 26 Oct 2011 21:17:34 +0200
    Subject: [PATCH 1/2] Add NFData instances for strict and lazy ByteStrings
    
    ---
     Data/ByteString/Internal.hs      |    4 ++++
     Data/ByteString/Lazy/Internal.hs |    6 ++++++
     bytestring.cabal                 |    4 ++--
     3 files changed, 12 insertions(+), 2 deletions(-)
    
    diff --git a/Data/ByteString/Internal.hs b/Data/ByteString/Internal.hs
    index 938f2a1..1dce1c1 100644
    a b import Foreign.Storable (Storable(..)) 
    7171import Foreign.C.Types          (CInt(..), CSize(..), CULong(..)) 
    7272import Foreign.C.String         (CString) 
    7373 
     74import Control.DeepSeq          (NFData) 
     75 
    7476#ifndef __NHC__ 
    7577import Control.Exception        (assert) 
    7678#endif 
    data ByteString = PS {-# UNPACK #-} !(ForeignPtr Word8) -- payload 
    157159    deriving (Data, Typeable) 
    158160#endif 
    159161 
     162instance NFData ByteString 
     163 
    160164instance Show ByteString where 
    161165    showsPrec p ps r = showsPrec p (unpackWith w2c ps) r 
    162166 
  • Data/ByteString/Lazy/Internal.hs

    diff --git a/Data/ByteString/Lazy/Internal.hs b/Data/ByteString/Lazy/Internal.hs
    index 52ba17b..6489f6c 100644
    a b import qualified Data.ByteString.Internal as S 
    4040 
    4141import Foreign.Storable (Storable(sizeOf)) 
    4242 
     43import Control.DeepSeq (NFData, rnf) 
     44 
    4345#if defined(__GLASGOW_HASKELL__) 
    4446import Data.Typeable    (Typeable) 
    4547#if __GLASGOW_HASKELL__ >= 610 
    data ByteString = Empty | Chunk {-# UNPACK #-} !S.ByteString ByteString 
    6163#endif 
    6264             ) 
    6365 
     66instance NFData ByteString where 
     67    rnf Empty       = () 
     68    rnf (Chunk _ b) = rnf b 
     69 
    6470------------------------------------------------------------------------ 
    6571 
    6672-- | The data type invariant: 
  • bytestring.cabal

    diff --git a/bytestring.cabal b/bytestring.cabal
    index 8c6ee23..ec86c75 100644
    a b Cabal-Version: >= 1.8 
    2727extra-source-files:  README TODO 
    2828 
    2929library 
    30   build-depends:     base >= 3 && < 5 
     30  build-depends:     base >= 3 && < 5, deepseq 
    3131 
    3232  if impl(ghc >= 6.10) 
    3333    build-depends:   ghc-prim, base >= 4 
    test-suite prop-compiled 
    7171  type:             exitcode-stdio-1.0 
    7272  main-is:          Properties.hs 
    7373  hs-source-dirs:   . tests 
    74   build-depends:    base, random, directory, 
     74  build-depends:    base, deepseq, random, directory, 
    7575                    QuickCheck >= 2.3 && < 3 
    7676  if impl(ghc >= 6.10) 
    7777    build-depends:  ghc-prim