ptr-poker 0.1.1.4 → 0.1.2
raw patch · 6 files changed
+213/−21 lines, 6 filesdep ~textPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: text
API changes (from Hackage documentation)
+ PtrPoker.Poke: bInt16 :: Int16 -> Poke
+ PtrPoker.Poke: bInt32 :: Int32 -> Poke
+ PtrPoker.Poke: bInt64 :: Int64 -> Poke
+ PtrPoker.Poke: bWord16 :: Word16 -> Poke
+ PtrPoker.Poke: bWord32 :: Word32 -> Poke
+ PtrPoker.Poke: lInt16 :: Int16 -> Poke
+ PtrPoker.Poke: lInt32 :: Int32 -> Poke
+ PtrPoker.Poke: lInt64 :: Int64 -> Poke
+ PtrPoker.Poke: lWord16 :: Word16 -> Poke
+ PtrPoker.Poke: lWord32 :: Word32 -> Poke
+ PtrPoker.Write: bInt16 :: Int16 -> Write
+ PtrPoker.Write: bInt32 :: Int32 -> Write
+ PtrPoker.Write: bInt64 :: Int64 -> Write
+ PtrPoker.Write: bWord16 :: Word16 -> Write
+ PtrPoker.Write: bWord32 :: Word32 -> Write
+ PtrPoker.Write: bWord64 :: Word64 -> Write
+ PtrPoker.Write: lInt16 :: Int16 -> Write
+ PtrPoker.Write: lInt32 :: Int32 -> Write
+ PtrPoker.Write: lInt64 :: Int64 -> Write
+ PtrPoker.Write: lWord16 :: Word16 -> Write
+ PtrPoker.Write: lWord32 :: Word32 -> Write
+ PtrPoker.Write: lWord64 :: Word64 -> Write
Files
- bench/Main.hs +8/−0
- library/PtrPoker/ByteString.hs +7/−2
- library/PtrPoker/Poke.hs +81/−3
- library/PtrPoker/Size.hs +7/−2
- library/PtrPoker/Write.hs +108/−12
- ptr-poker.cabal +2/−2
bench/Main.hs view
@@ -8,6 +8,14 @@ main = defaultMain [+ bgroup "bWord32" [+ bench "4"+ $ nf+ (\(a,b,c,d) -> Write.writeToByteString $+ Write.bWord32 a <> Write.bWord32 b <> Write.bWord32 c <> Write.bWord32 d)+ (1,2,3,4)+ ]+ , bgroup "textUtf8" $ let latinSampleBySize size = enumFromTo 'a' 'z' &
library/PtrPoker/ByteString.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} module PtrPoker.ByteString where @@ -42,11 +43,15 @@ {-# INLINABLE textUtf8 #-} textUtf8 :: Text -> ByteString-textUtf8 (TextInternal.Text arr off len) =+#if MIN_VERSION_text(2,0,0)+textUtf8 (TextInternal.Text (TextArray.ByteArray arr) off len) =+#else+textUtf8 (TextInternal.Text (TextArray.aBA -> arr) off len) =+#endif if len == 0 then empty else unsafeCreateUptoN (len * 3) $ \ ptr -> do- postPtr <- inline Ffi.encodeText ptr (TextArray.aBA arr) (fromIntegral off) (fromIntegral len)+ postPtr <- inline Ffi.encodeText ptr arr (fromIntegral off) (fromIntegral len) return (minusPtr postPtr ptr)
library/PtrPoker/Poke.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} module PtrPoker.Poke where @@ -67,6 +68,38 @@ Poke (\ p -> PrimIO.pokeWord8 p a $> plusPtr p 1) {-|+Encode Word16 in Little-endian.+-}+{-# INLINE[1] lWord16 #-}+lWord16 :: Word16 -> Poke+lWord16 a =+ Poke (\ p -> PrimIO.pokeLEWord16 p a $> plusPtr p 2)++{-|+Encode Word16 in Big-endian.+-}+{-# INLINE[1] bWord16 #-}+bWord16 :: Word16 -> Poke+bWord16 a =+ Poke (\ p -> PrimIO.pokeBEWord16 p a $> plusPtr p 2)++{-|+Encode Word32 in Little-endian.+-}+{-# INLINE[1] lWord32 #-}+lWord32 :: Word32 -> Poke+lWord32 a =+ Poke (\ p -> PrimIO.pokeLEWord32 p a $> plusPtr p 4)++{-|+Encode Word32 in Big-endian.+-}+{-# INLINE[1] bWord32 #-}+bWord32 :: Word32 -> Poke+bWord32 a =+ Poke (\ p -> PrimIO.pokeBEWord32 p a $> plusPtr p 4)++{-| Encode Word64 in Little-endian. -} {-# INLINE[1] lWord64 #-}@@ -83,13 +116,58 @@ Poke (\ p -> PrimIO.pokeBEWord64 p a $> plusPtr p 8) {-|+Encode Int16 in Little-endian.+-}+{-# INLINE lInt16 #-}+lInt16 :: Int16 -> Poke+lInt16 = lWord16 . fromIntegral++{-|+Encode Int16 in Big-endian.+-}+{-# INLINE bInt16 #-}+bInt16 :: Int16 -> Poke+bInt16 = bWord16 . fromIntegral++{-|+Encode Int32 in Little-endian.+-}+{-# INLINE lInt32 #-}+lInt32 :: Int32 -> Poke+lInt32 = lWord32 . fromIntegral++{-|+Encode Int32 in Big-endian.+-}+{-# INLINE bInt32 #-}+bInt32 :: Int32 -> Poke+bInt32 = bWord32 . fromIntegral++{-|+Encode Int64 in Little-endian.+-}+{-# INLINE lInt64 #-}+lInt64 :: Int64 -> Poke+lInt64 = lWord64 . fromIntegral++{-|+Encode Int64 in Big-endian.+-}+{-# INLINE bInt64 #-}+bInt64 :: Int64 -> Poke+bInt64 = bWord64 . fromIntegral++{-| Encode Text in UTF8. -} {-# INLINE textUtf8 #-} textUtf8 :: Text -> Poke-textUtf8 (Text.Text arr off len) =- Poke (\ p -> Ffi.encodeText p (TextArray.aBA arr) (fromIntegral off) (fromIntegral len))-+#if MIN_VERSION_text(2,0,0)+textUtf8 (Text.Text (TextArray.ByteArray arr) off len) =+#else+textUtf8 (Text.Text (TextArray.aBA -> arr) off len) =+#endif+ Poke (\ p -> Ffi.encodeText p arr (fromIntegral off) (fromIntegral len)) -- * ASCII integers -------------------------
library/PtrPoker/Size.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-| Functions that compute the required allocation size by value. -}@@ -154,8 +155,12 @@ -} {-# INLINE textUtf8 #-} textUtf8 :: Text -> Int-textUtf8 (Text.Text arr off len) =+#if MIN_VERSION_text(2,0,0)+textUtf8 (Text.Text (TextArray.ByteArray arr) off len) =+#else+textUtf8 (Text.Text (TextArray.aBA -> arr) off len) =+#endif Ffi.countTextAllocationSize- (TextArray.aBA arr) (fromIntegral off) (fromIntegral len)+ arr (fromIntegral off) (fromIntegral len) & unsafeDupablePerformIO & fromIntegral
library/PtrPoker/Write.hs view
@@ -74,6 +74,102 @@ Write 1 (Poke.word8 a) {-|+Render Word16 in Little-endian.+-}+{-# INLINE lWord16 #-}+lWord16 :: Word16 -> Write+lWord16 a =+ Write 2 (Poke.lWord16 a)++{-|+Render Word16 in Big-endian.+-}+{-# INLINE bWord16 #-}+bWord16 :: Word16 -> Write+bWord16 a =+ Write 2 (Poke.bWord16 a)++{-|+Render Word32 in Little-endian.+-}+{-# INLINE lWord32 #-}+lWord32 :: Word32 -> Write+lWord32 a =+ Write 4 (Poke.lWord32 a)++{-|+Render Word32 in Big-endian.+-}+{-# INLINE bWord32 #-}+bWord32 :: Word32 -> Write+bWord32 a =+ Write 4 (Poke.bWord32 a)++{-|+Render Word64 in Little-endian.+-}+{-# INLINE lWord64 #-}+lWord64 :: Word64 -> Write+lWord64 a =+ Write 8 (Poke.lWord64 a)++{-|+Render Word64 in Big-endian.+-}+{-# INLINE bWord64 #-}+bWord64 :: Word64 -> Write+bWord64 a =+ Write 8 (Poke.bWord64 a)++{-|+Render Int16 in Little-endian.+-}+{-# INLINE lInt16 #-}+lInt16 :: Int16 -> Write+lInt16 a =+ Write 2 (Poke.lInt16 a)++{-|+Render Int16 in Big-endian.+-}+{-# INLINE bInt16 #-}+bInt16 :: Int16 -> Write+bInt16 a =+ Write 2 (Poke.bInt16 a)++{-|+Render Int32 in Little-endian.+-}+{-# INLINE lInt32 #-}+lInt32 :: Int32 -> Write+lInt32 a =+ Write 4 (Poke.lInt32 a)++{-|+Render Int32 in Big-endian.+-}+{-# INLINE bInt32 #-}+bInt32 :: Int32 -> Write+bInt32 a =+ Write 4 (Poke.bInt32 a)++{-|+Render Int64 in Little-endian.+-}+{-# INLINE lInt64 #-}+lInt64 :: Int64 -> Write+lInt64 a =+ Write 8 (Poke.lInt64 a)++{-|+Render Int64 in Big-endian.+-}+{-# INLINE bInt64 #-}+bInt64 :: Int64 -> Write+bInt64 a =+ Write 8 (Poke.bInt64 a)++{-| Render Word64 in ASCII decimal. -} {-# INLINE word64AsciiDec #-}@@ -181,18 +277,18 @@ === __Benchmark results__ -> textUtf8/ptr-poker/latin/1 mean 57.06 ns ( +- 3.283 ns )-> textUtf8/ptr-poker/latin/10 mean 214.1 ns ( +- 8.601 ns )-> textUtf8/ptr-poker/latin/100 mean 1.536 μs ( +- 75.03 ns )-> textUtf8/ptr-poker/greek/1 mean 85.98 ns ( +- 5.038 ns )-> textUtf8/ptr-poker/greek/10 mean 482.1 ns ( +- 12.38 ns )-> textUtf8/ptr-poker/greek/100 mean 4.398 μs ( +- 33.94 ns )-> textUtf8/text/latin/1 mean 60.28 ns ( +- 3.517 ns )-> textUtf8/text/latin/10 mean 201.6 ns ( +- 8.118 ns )-> textUtf8/text/latin/100 mean 1.323 μs ( +- 51.25 ns )-> textUtf8/text/greek/1 mean 99.14 ns ( +- 1.264 ns )-> textUtf8/text/greek/10 mean 483.4 ns ( +- 5.844 ns )-> textUtf8/text/greek/100 mean 4.238 μs ( +- 40.55 ns )+> textUtf8/ptr-poker/latin/1 mean 51.54 ns ( +- 3.083 ns )+> textUtf8/ptr-poker/latin/10 mean 132.8 ns ( +- 14.75 ns )+> textUtf8/ptr-poker/latin/100 mean 860.6 ns ( +- 66.61 ns )+> textUtf8/ptr-poker/greek/1 mean 106.4 ns ( +- 19.28 ns )+> textUtf8/ptr-poker/greek/10 mean 498.4 ns ( +- 8.022 ns )+> textUtf8/ptr-poker/greek/100 mean 4.462 μs ( +- 31.58 ns )+> textUtf8/text/latin/1 mean 52.77 ns ( +- 3.311 ns )+> textUtf8/text/latin/10 mean 206.1 ns ( +- 26.78 ns )+> textUtf8/text/latin/100 mean 1.337 μs ( +- 43.34 ns )+> textUtf8/text/greek/1 mean 88.22 ns ( +- 1.119 ns )+> textUtf8/text/greek/10 mean 475.2 ns ( +- 21.15 ns )+> textUtf8/text/greek/100 mean 4.252 μs ( +- 64.33 ns ) -} {-# INLINABLE textUtf8 #-} textUtf8 :: Text -> Write
ptr-poker.cabal view
@@ -1,5 +1,5 @@ name: ptr-poker-version: 0.1.1.4+version: 0.1.2 synopsis: Pointer poking action construction and composition toolkit homepage: https://github.com/nikita-volkov/ptr-poker bug-reports: https://github.com/nikita-volkov/ptr-poker/issues@@ -39,7 +39,7 @@ base >=4.11 && <5, bytestring >=0.10 && <0.12, scientific >=0.3.6.2 && <0.4,- text >=1 && <2+ text >=1 && <3 test-suite test type: exitcode-stdio-1.0