packages feed

fast-builder 0.0.0.3 → 0.0.0.4

raw patch · 2 files changed

+64/−5 lines, 2 files

Files

+ benchmarks/aeson/template.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}+module NAME+  ( fromValue+  , valueToLazyByteString+  ) where++#ifndef LIB+#define LIB Data.ByteString.FastBuilder+#endif++import Data.Aeson+import qualified Data.ByteString.Lazy as L+import Data.Monoid+import qualified Data.Scientific as Sci+import qualified Data.Text as T+import qualified Data.Text.Encoding as T+import qualified Data.Vector as V++import LIB+import HashMapExts++valueToLazyByteString :: Value -> L.ByteString+valueToLazyByteString = toLazyByteString . fromValue++fromValue :: Value -> Builder+-- fromValue v = fromValue' v+fromValue v = rebuild $ fromValue' v++fromValue' :: Value -> Builder+fromValue' (Object o) = fromObject o+fromValue' (Array a) = fromArray a+fromValue' (String s) = fromString s+fromValue' (Number n) = fromNumber n+fromValue' (Bool False) = "false"+fromValue' (Bool True) = "true"+fromValue' Null = "null"+{-# INLINE fromValue' #-}++fromArray :: Array -> Builder+fromArray arr = V.foldr f (const $ char8 ']') arr True+  where+    f x r initial =+      (if initial then char8 '[' else char8 ',')+      <> fromValue x <> r False++fromString :: T.Text -> Builder+fromString str = byteString $ T.encodeUtf8 str++fromNumber :: Sci.Scientific -> Builder+fromNumber = either doubleDec integerDec . Sci.floatingOrInteger++fromObject :: Object -> Builder+fromObject obj = char8 '{' <> foldMapWithKey f obj <> char8 '}'+  where+      f k v =+        fromString k <> char8 ':' <> fromValue v+        <> char8 ','
fast-builder.cabal view
@@ -1,5 +1,5 @@ name:                fast-builder-version:             0.0.0.3+version:             0.0.0.4 synopsis:            Fast ByteString Builder description:         An efficient implementation of ByteString builder. It should be faster than                      the standard implementation in most cases.@@ -10,10 +10,10 @@ license-file:        LICENSE author:              Takano Akio maintainer:          aljee@hyper.cx--- copyright:           +-- copyright: category:            Data build-type:          Simple--- extra-source-files:  +extra-source-files:  benchmarks/aeson/*.hs cabal-version:       >=1.10 tested-with:         GHC >= 7.10.1 && < 8 @@ -22,9 +22,9 @@                        Data.ByteString.FastBuilder.Internal   other-modules:       Data.ByteString.FastBuilder.Internal.Prim -  -- other-extensions:    +  -- other-extensions:   build-depends:       base >= 4.8 && < 4.9, bytestring >= 0.10.6.0, ghc-prim-  -- hs-source-dirs:      +  -- hs-source-dirs:   default-language:    Haskell2010   ghc-options:         -Wall -g @@ -33,6 +33,7 @@   main-is:             main.hs   hs-source-dirs:      benchmarks/aeson   other-modules:       Fast, Bstr, HashMapExts+  include-dirs:        benchmarks/aeson   build-depends:       base, fast-builder, aeson, criterion, bytestring,     scientific, text, vector, deepseq, unordered-containers, ghc-prim,     template-haskell, true-name >= 0.1.0.0