packages feed

ptr 0.16.4 → 0.16.5

raw patch · 3 files changed

+38/−2 lines, 3 filesdep +vector

Dependencies added: vector

Files

library/Ptr/Poke.hs view
@@ -3,6 +3,7 @@  import Ptr.Prelude import qualified Ptr.PokeAndPeek as B+import qualified Data.Vector as F   {-|@@ -84,3 +85,16 @@ asciiHexDigit :: Poke Word8 asciiHexDigit =   contramap (\ n -> if n < 10 then 48 + n else 55 + n) word8++{-# INLINE vector #-}+vector :: Int -> Poke element -> Poke (F.Vector element)+vector vectorSize (Poke elementByteSize elementIO) =+  Poke vectorByteSize vectorIO+  where+    vectorByteSize =+      vectorSize * elementByteSize+    vectorIO =+      F.foldM'_ step+      where+        step ptr element =+          elementIO ptr element $> plusPtr ptr elementByteSize
library/Ptr/Poking.hs view
@@ -7,6 +7,7 @@ import qualified Ptr.PokeAndPeek as D import qualified Ptr.PokeIO as E import qualified Data.ByteString.Internal as B+import qualified Data.Vector as F   {-|@@ -20,7 +21,7 @@   * Amount of bytes the encoded data will occupy.   * Exception-free action, which populates the pointer to the encoded data.   -}-  Poking !Int !(Ptr Word8 -> IO ())+  Poking !Int (Ptr Word8 -> IO ())  instance Semigroup Poking where   {-|@@ -169,3 +170,23 @@       \ case         head : tail -> loop (state <> word8 1 <> element head) tail         _ -> state <> word8 0++{-# INLINABLE vector #-}+vector :: (element -> Poking) -> F.Vector element -> Poking+vector element vectorValue =+  Poking byteSize io+  where+    byteSize =+      foldl' step 0 vectorValue+      where+        step !byteSize elementValue =+          case element elementValue of+            Poking elementByteSize _ -> byteSize + elementByteSize+    io ptr =+      F.foldM'_ step ptr vectorValue+      where+        step ptr elementValue =+          case element elementValue of+            Poking elementByteSize elementIO -> do+              elementIO ptr+              return (plusPtr ptr elementByteSize)
ptr.cabal view
@@ -1,7 +1,7 @@ name:   ptr version:-  0.16.4+  0.16.5 category:   Ptr, Data synopsis:@@ -58,6 +58,7 @@     text == 1.*,     bytestring >= 0.10 && < 0.11,     time >= 1 && < 2,+    vector >= 0.12 && < 0.13,     -- control:     semigroups >= 0.18 && < 0.20,     profunctors >= 5.1 && < 6,