Commits

Bryan O'Sullivan committed 311c977

NFData instances for the Result types.

Comments (0)

Files changed (2)

Data/Attoparsec/ByteString/Lazy.hs

     , eitherResult
     ) where
 
+import Control.DeepSeq (NFData(rnf))
 import Data.ByteString.Lazy.Internal (ByteString(..), chunk)
 import qualified Data.ByteString as B
 import qualified Data.Attoparsec.ByteString as A
               -- input that had not yet been consumed (if any) when
               -- the parse succeeded.
 
+instance NFData r => NFData (Result r) where
+    rnf (Fail bs ctxs msg) = rnfBS bs `seq` rnf ctxs `seq` rnf msg
+    rnf (Done bs r)        = rnfBS bs `seq` rnf r
+    {-# INLINE rnf #-}
+
+rnfBS :: ByteString -> ()
+rnfBS (Chunk _ xs) = rnfBS xs
+rnfBS Empty        = ()
+{-# INLINE rnfBS #-}
+
 instance Show r => Show (Result r) where
     show (Fail bs stk msg) =
         "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg

Data/Attoparsec/Text/Lazy.hs

     , eitherResult
     ) where
 
+import Control.DeepSeq (NFData(rnf))
 import Data.Text.Lazy.Internal (Text(..), chunk)
 import qualified Data.Attoparsec.Internal.Types as T
 import qualified Data.Attoparsec.Text as A
         "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg
     show (Done bs r)       = "Done " ++ show bs ++ " " ++ show r
 
+instance NFData r => NFData (Result r) where
+    rnf (Fail bs ctxs msg) = rnf bs `seq` rnf ctxs `seq` rnf msg
+    rnf (Done bs r)        = rnf bs `seq` rnf r
+    {-# INLINE rnf #-}
+
 fmapR :: (a -> b) -> Result a -> Result b
 fmapR _ (Fail st stk msg) = Fail st stk msg
 fmapR f (Done bs r)       = Done bs (f r)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.