summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench/Main.hs10
-rw-r--r--bencoding.cabal4
-rw-r--r--src/Data/BEncode.hs7
3 files changed, 11 insertions, 10 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index 2edf43a..20de179 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -15,7 +15,6 @@ import Data.AttoBencode as B
15import Data.AttoBencode.Parser as B 15import Data.AttoBencode.Parser as B
16import "bencoding" Data.BEncode as C 16import "bencoding" Data.BEncode as C
17 17
18
19instance NFData A.BEncode where 18instance NFData A.BEncode where
20 rnf (A.BInt i) = rnf i 19 rnf (A.BInt i) = rnf i
21 rnf (A.BString s) = rnf s 20 rnf (A.BString s) = rnf s
@@ -28,15 +27,8 @@ instance NFData B.BValue where
28 rnf (B.BList l) = rnf l 27 rnf (B.BList l) = rnf l
29 rnf (B.BDict d) = rnf d 28 rnf (B.BDict d) = rnf d
30 29
31instance NFData C.BEncode where
32 rnf (C.BInteger i) = rnf i
33 rnf (C.BString s) = rnf s
34 rnf (C.BList l) = rnf l
35 rnf (C.BDict d) = rnf d
36
37getRight :: Either String a -> a 30getRight :: Either String a -> a
38getRight (Left e) = error e 31getRight = either error id
39getRight (Right x) = x
40 32
41main :: IO () 33main :: IO ()
42main = do 34main = do
diff --git a/bencoding.cabal b/bencoding.cabal
index 7918508..0aa251a 100644
--- a/bencoding.cabal
+++ b/bencoding.cabal
@@ -20,7 +20,8 @@ description:
20 * /0.1.0.0:/ Initial version. 20 * /0.1.0.0:/ Initial version.
21 21
22 22
23extra-source-files: README.md .travis.yml 23extra-source-files: README.md
24 .travis.yml
24 25
25source-repository head 26source-repository head
26 type: git 27 type: git
@@ -30,6 +31,7 @@ source-repository head
30library 31library
31 exposed-modules: Data.BEncode 32 exposed-modules: Data.BEncode
32 build-depends: base == 4.* 33 build-depends: base == 4.*
34 , deepseq == 1.3.*
33 , containers >= 0.4 35 , containers >= 0.4
34 , bytestring >= 0.10.0.0 36 , bytestring >= 0.10.0.0
35 , attoparsec >= 0.10 37 , attoparsec >= 0.10
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index 62188ff..b53f6e5 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -102,6 +102,7 @@ module Data.BEncode
102 102
103 103
104import Control.Applicative 104import Control.Applicative
105import Control.DeepSeq
105import Control.Monad 106import Control.Monad
106import Data.Int 107import Data.Int
107import Data.Maybe (mapMaybe) 108import Data.Maybe (mapMaybe)
@@ -146,6 +147,12 @@ data BEncode = BInteger {-# UNPACK #-} !Int64
146 | BDict Dict 147 | BDict Dict
147 deriving (Show, Read, Eq, Ord) 148 deriving (Show, Read, Eq, Ord)
148 149
150instance NFData BEncode where
151 rnf (BInteger i) = rnf i
152 rnf (BString s) = rnf s
153 rnf (BList l) = rnf l
154 rnf (BDict d) = rnf d
155
149-- | Result used in decoding operations. 156-- | Result used in decoding operations.
150type Result = Either String 157type Result = Either String
151 158