on master help sign in
Speed up the encoding of numbers.
commit17a613b2f0fba00493fa95151bb18a515bd34585 authorBryan O'Sullivan <bos@mailrank.com> dateTue 8 Mar 2011, 16:30 (16 years ago) parentee7be03
2 files changed+6−3
Data/Aeson/Encode.hs+5−3 aeson.cabal+1
Data/Aeson/Encode.hs+5−3
@@ -18,19 +18,21 @@ module Data.Aeson.Encode
1818import Blaze.ByteString.Builder
1919import Blaze.ByteString.Builder.Char.Utf8
2020import Data.Aeson.Types (ToJSON(..), Value(..))
21+import Data.Attoparsec.Number (Number(..))
2122import Data.Monoid (mappend)
2223import Numeric (showHex)
23−import qualified Data.ByteString.Char8 as B
2424import qualified Data.ByteString.Lazy.Char8 as L
2525import qualified Data.Map as M
2626import qualified Data.Text as T
2727import qualified Data.Vector as V
28+import qualified Text.Show.ByteString as S
2829
2930-- | Encode a JSON value to a 'Builder'.
3031fromValue :: Value -> Builder
3132fromValue Null = fromByteString "null"
3233fromValue (Bool b) = fromByteString $ if b then "true" else "false"
33−fromValue (Number n) = fromByteString (B.pack (show n))
34+fromValue (Number (I n)) = fromLazyByteString (S.show n)
35+fromValue (Number (D n)) = fromLazyByteString (S.show n)
3436fromValue (String s) = string s
3537fromValue (Array v)
3638 | V.null v = fromByteString "[]"
@@ -52,7 +54,7 @@ string s = fromChar '"' `mappend` quote s `mappend` fromChar '"'
5254 where
5355 quote q = case T.uncons t of
5456 Just (c,t') -> fromText h `mappend` escape c `mappend` quote t'
55− Nothing -> fromText h
57+ Nothing -> fromText h
5658 where (h,t) = T.break isEscape q
5759 isEscape c = c == '\"' || c == '\\' || c < '\x20'
5860 escape '\"' = fromByteString "\\\""
aeson.cabal+1
@@ -90,6 +90,7 @@ library
9090 base == 4.*,
9191 blaze-builder >= 0.2.1.4,
9292 bytestring,
93+ bytestring-show,
9394 containers,
9495 deepseq,
9596 hashable,