[commit: packages/binary] master: Add 'putList' instance for Word8. (d87fd41)

git at git.haskell.org git at git.haskell.org
Tue Apr 19 20:30:20 UTC 2016


Repository : ssh://git@git.haskell.org/binary

On branch  : master
Link       : http://git.haskell.org/packages/binary.git/commitdiff/d87fd415ceaf318bf37c3bd0940aedd5303b053f

>---------------------------------------------------------------

commit d87fd415ceaf318bf37c3bd0940aedd5303b053f
Author: Lennart Kolmodin <kolmodin at gmail.com>
Date:   Mon Apr 4 22:31:03 2016 +0200

    Add 'putList' instance for Word8.
    
    Highlights from the benchmarks;
      "big Integers"                                         :      5850.12 us        3841.54 us      -34.3%
      "[big Integer]"                                        :      6074.67 us        3959.01 us      -34.8%
      Word8s                                                 :       256.19 us         266.92 us      +4.2%
      [Word8]                                                :       283.39 us          67.59 us      -76.2%


>---------------------------------------------------------------

d87fd415ceaf318bf37c3bd0940aedd5303b053f
 src/Data/Binary/Class.hs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs
index 161f2a7..36fc681 100644
--- a/src/Data/Binary/Class.hs
+++ b/src/Data/Binary/Class.hs
@@ -68,6 +68,7 @@ import Control.Monad
 
 import Data.ByteString.Lazy (ByteString)
 import qualified Data.ByteString.Lazy as L
+import qualified Data.ByteString.Builder.Prim as Prim
 
 import Data.List    (unfoldr, foldl')
 
@@ -209,6 +210,9 @@ instance Binary Ordering where
 -- Words8s are written as bytes
 instance Binary Word8 where
     put     = putWord8
+    putList xs = do
+        put (length xs)
+        putBuilder (Prim.primMapListFixed Prim.word8 xs)
     get     = getWord8
 
 -- Words16s are written as 2 bytes in big-endian (network) order



More information about the ghc-commits mailing list