{-# LANGUAGE CPP #-} module PtrPoker.Compat.ByteString where #if MIN_VERSION_bytestring(0,11,0) import Data.ByteString.Internal import PtrPoker.Prelude {-# INLINE poke #-} poke :: ByteString -> Ptr Word8 -> IO (Ptr Word8) poke :: ByteString -> Ptr Word8 -> IO (Ptr Word8) poke (BS ForeignPtr Word8 fptr Int length) Ptr Word8 ptr = {-# SCC "poke" #-} forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b withForeignPtr ForeignPtr Word8 fptr forall a b. (a -> b) -> a -> b $ \ Ptr Word8 bytesPtr -> Ptr Word8 -> Ptr Word8 -> Int -> IO () memcpy Ptr Word8 ptr Ptr Word8 bytesPtr Int length forall (f :: * -> *) a b. Functor f => f a -> b -> f b $> forall a b. Ptr a -> Int -> Ptr b plusPtr Ptr Word8 ptr Int length #else import Data.ByteString.Internal import PtrPoker.Prelude {-# INLINE poke #-} poke :: ByteString -> Ptr Word8 -> IO (Ptr Word8) poke (PS fptr offset length) ptr = {-# SCC "poke" #-} withForeignPtr fptr $ \ bytesPtr -> memcpy ptr (plusPtr bytesPtr offset) length $> plusPtr ptr length #endif