{-# LANGUAGE CPP #-} module PtrPoker.IO.ByteString where import Data.ByteString.Internal import PtrPoker.Prelude #if MIN_VERSION_bytestring(0,11,0) {-# INLINE pokeByteString #-} pokeByteString :: Ptr Word8 -> ByteString -> IO (Ptr Word8) pokeByteString :: Ptr Word8 -> ByteString -> IO (Ptr Word8) pokeByteString Ptr Word8 ptr (BS ForeignPtr Word8 fptr Int length) = {-# SCC "pokeByteString" #-} 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 {-# INLINE pokeByteString #-} pokeByteString :: Ptr Word8 -> ByteString -> IO (Ptr Word8) pokeByteString ptr (PS fptr offset length) = {-# SCC "pokeByteString" #-} withForeignPtr fptr $ \ bytesPtr -> memcpy ptr (plusPtr bytesPtr offset) length $> plusPtr ptr length #endif