Commits

Bryan O'Sullivan committed bc5572a

Add an NFData instance for Value

Comments (0)

Files changed (3)

Data/Aeson/Types.hs

     ) where
 
 import Control.Applicative
+import Control.DeepSeq
 import Data.Map (Map)
 import Data.Text (Text, pack, unpack)
 import Data.Time.Clock (UTCTime)
            | Null
              deriving (Eq, Show, Typeable)
 
+instance NFData Value where
+    rnf (Object o) = rnf o
+    rnf (Array a)  = V.foldl' (\x y -> rnf y `seq` x) () a
+    rnf (String s) = rnf s
+    rnf (Number n) = rnf n
+    rnf (Bool b)   = rnf b
+    rnf Null       = ()
+
 (.=) :: ToJSON a => Text -> a -> Object
 name .= value = M.singleton name (toJSON value)
 {-# INLINE (.=) #-}
     blaze-builder >= 0.2.1.4,
     bytestring,
     containers == 0.3.*,
+    deepseq,
     old-locale,
     text >= 0.11.0.2,
     time,

benchmarks/ParseFile.hs

 {-# LANGUAGE BangPatterns, OverloadedStrings #-}
 
+import Control.DeepSeq
 import Control.Exception
 import Control.Monad
 import Data.Aeson
           let refill = B.hGet h 1024
           result <- parseWith refill json =<< refill
           case result of
-            Done _ _ -> loop (good+1) bad
+            Done _ r -> rnf r `seq` loop (good+1) bad
             _        -> loop good (bad+1)
     (good, _) <- loop 0 0
     end <- getCurrentTime