on master help sign in
Get rid of the old decode function
4667a18Bryan O'Sullivan
Data/Text/Encoding.hs+8−20
@@ -22,14 +22,12 @@ module Data.Text.Encoding
22 -- * Decoding ByteStrings to Text
22 -- * Decoding ByteStrings to Text
23 decodeASCII
23 decodeASCII
24 , decodeUtf8
24 , decodeUtf8
25− , decodeUtf8'
26 , decodeUtf16LE
25 , decodeUtf16LE
27 , decodeUtf16BE
26 , decodeUtf16BE
28 , decodeUtf32LE
27 , decodeUtf32LE
29 , decodeUtf32BE
28 , decodeUtf32BE
30 -- ** Controllable error handling
29 -- ** Controllable error handling
31 , decodeUtf8With
30 , decodeUtf8With
32− , decodeUtf8With'
33 , decodeUtf16LEWith
31 , decodeUtf16LEWith
34 , decodeUtf16BEWith
32 , decodeUtf16BEWith
35 , decodeUtf32LEWith
33 , decodeUtf32LEWith
@@ -67,18 +65,8 @@ decodeASCII :: ByteString -> Text
67decodeASCII bs = F.unstream (E.streamASCII bs)
65decodeASCII bs = F.unstream (E.streamASCII bs)
68{-# INLINE decodeASCII #-}
66{-# INLINE decodeASCII #-}
69
67
70−-- | Decode a 'ByteString' containing UTF-8 encoded text.
71decodeUtf8With :: OnDecodeError -> ByteString -> Text
68decodeUtf8With :: OnDecodeError -> ByteString -> Text
72−decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
69+decodeUtf8With onErr bs = textP (fst a) 0 (snd a)
73−{-# INLINE decodeUtf8With #-}
74−
75−-- | Decode a 'ByteString' containing UTF-8 encoded text.
76−decodeUtf8 :: ByteString -> Text
77−decodeUtf8 = decodeUtf8With strictDecode
78−{-# INLINE decodeUtf8 #-}
79−
80−decodeUtf8With' :: OnDecodeError -> ByteString -> Text
81−decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
82 where
70 where
83 a = A.run2 (A.new len >>= outer 0 0)
71 a = A.run2 (A.new len >>= outer 0 0)
84 len = B.length bs
72 len = B.length bs
@@ -109,16 +97,16 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
109 Just c -> do
97 Just c -> do
110 w <- unsafeWrite arr n c
98 w <- unsafeWrite arr n c
111 go (n+w) (m+1)
99 go (n+w) (m+1)
112− desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
100+ desc = "Data.Text.Encoding.decodeUtf8: Invalid UTF-8 stream"
113−{-# INLINE[0] decodeUtf8With' #-}
101+{-# INLINE[0] decodeUtf8With #-}
114
102
115-- | Decode a 'ByteString' containing UTF-8 encoded text.
103-- | Decode a 'ByteString' containing UTF-8 encoded text.
116−decodeUtf8' :: ByteString -> Text
104+decodeUtf8 :: ByteString -> Text
117−decodeUtf8' = decodeUtf8With' strictDecode
105+decodeUtf8 = decodeUtf8With strictDecode
118−{-# INLINE[0] decodeUtf8' #-}
106+{-# INLINE[0] decodeUtf8 #-}
119
107
120−{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
108+{-# RULES "STREAM stream/decodeUtf8 fusion" [1]
121− forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
109+ forall bs. F.stream (decodeUtf8 bs) = E.streamUtf8 strictDecode bs #-}
122
110
123-- | Encode text using UTF-8 encoding.
111-- | Encode text using UTF-8 encoding.
124encodeUtf8 :: Text -> ByteString
112encodeUtf8 :: Text -> ByteString
tests/benchmarks/DecodeUtf8.hs+10−9
@@ -15,23 +15,24 @@ strict h = do
15 bs <- B.hGetContents h
15 bs <- B.hGetContents h
16 rnf (T.decodeUtf8 bs) `seq` return ()
16 rnf (T.decodeUtf8 bs) `seq` return ()
17
17
18−strict_ h = do
19− bs <- B.hGetContents h
20− rnf (T.decodeUtf8' bs) `seq` return ()
21−
22strict_len h = do
18strict_len h = do
23 bs <- B.hGetContents h
19 bs <- B.hGetContents h
24− print . T.length . T.init . T.decodeUtf8 $ bs
20+ print . T.length . T.decodeUtf8 $ bs
25
21
26−strict__len h = do
22+strict_init_len h = do
27 bs <- B.hGetContents h
23 bs <- B.hGetContents h
28− print . T.length . T.init . T.decodeUtf8' $ bs
24+ print . T.length . T.init . T.decodeUtf8 $ bs
29
25
30strict_io h = do
26strict_io h = do
31 hSetEncoding h utf8
27 hSetEncoding h utf8
32 t <- T.hGetContents h
28 t <- T.hGetContents h
33 rnf t `seq` return ()
29 rnf t `seq` return ()
34
30
31+strict_len_io h = do
32+ hSetEncoding h utf8
33+ t <- T.hGetContents h
34+ print (T.length t)
35+
35lazy h = do
36lazy h = do
36 bs <- BL.hGetContents h
37 bs <- BL.hGetContents h
37 rnf (TL.decodeUtf8 bs) `seq` return ()
38 rnf (TL.decodeUtf8 bs) `seq` return ()
@@ -51,10 +52,10 @@ main = do
51 h <- openFile name ReadMode
52 h <- openFile name ReadMode
52 case kind of
53 case kind of
53 "strict" -> strict h
54 "strict" -> strict h
54− "strict_" -> strict_ h
55− "strict__len" -> strict__len h
56 "strict_len" -> strict_len h
55 "strict_len" -> strict_len h
56+ "strict_init_len" -> strict_init_len h
57 "strict_io" -> strict_io h
57 "strict_io" -> strict_io h
58+ "strict_len_io" -> strict_len_io h
58 "lazy" -> lazy h
59 "lazy" -> lazy h
59 "lazy_io" -> lazy_io h
60 "lazy_io" -> lazy_io h
60 "string" -> string h
61 "string" -> string h