on master help sign in
Get rid of the old decode function

--HG-- extra : convert_revision : 7e57067874ddcc3e6e87160e474005285c488abf

commit4667a184f421ca6f077eb91800cd8beb8285db94 authorBryan O'Sullivan <bos@serpentine.com> dateThu 14 Oct 2010, 23:02 (16 years ago) parentbe3f9d8
2 files changed+18−29
Data/Text/Encoding.hs+8−20 tests/benchmarks/DecodeUtf8.hs+10−9
Data/Text/Encoding.hs+8−20
@@ -22,14 +22,12 @@ module Data.Text.Encoding
2222 -- * Decoding ByteStrings to Text
2323 decodeASCII
2424 , decodeUtf8
25− , decodeUtf8'
2625 , decodeUtf16LE
2726 , decodeUtf16BE
2827 , decodeUtf32LE
2928 , decodeUtf32BE
3029 -- ** Controllable error handling
3130 , decodeUtf8With
32− , decodeUtf8With'
3331 , decodeUtf16LEWith
3432 , decodeUtf16BEWith
3533 , decodeUtf32LEWith
@@ -67,18 +65,8 @@ decodeASCII :: ByteString -> Text
6765decodeASCII bs = F.unstream (E.streamASCII bs)
6866{-# INLINE decodeASCII #-}
6967
70−-- | Decode a 'ByteString' containing UTF-8 encoded text.
7168decodeUtf8With :: OnDecodeError -> ByteString -> Text
72−decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
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)
69+decodeUtf8With onErr bs = textP (fst a) 0 (snd a)
8270 where
8371 a = A.run2 (A.new len >>= outer 0 0)
8472 len = B.length bs
@@ -109,16 +97,16 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
10997 Just c -> do
11098 w <- unsafeWrite arr n c
11199 go (n+w) (m+1)
112− desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
113−{-# INLINE[0] decodeUtf8With' #-}
100+ desc = "Data.Text.Encoding.decodeUtf8: Invalid UTF-8 stream"
101+{-# INLINE[0] decodeUtf8With #-}
114102
115103-- | Decode a 'ByteString' containing UTF-8 encoded text.
116−decodeUtf8' :: ByteString -> Text
117−decodeUtf8' = decodeUtf8With' strictDecode
118−{-# INLINE[0] decodeUtf8' #-}
104+decodeUtf8 :: ByteString -> Text
105+decodeUtf8 = decodeUtf8With strictDecode
106+{-# INLINE[0] decodeUtf8 #-}
119107
120−{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
121− forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
108+{-# RULES "STREAM stream/decodeUtf8 fusion" [1]
109+ forall bs. F.stream (decodeUtf8 bs) = E.streamUtf8 strictDecode bs #-}
122110
123111-- | Encode text using UTF-8 encoding.
124112encodeUtf8 :: Text -> ByteString
tests/benchmarks/DecodeUtf8.hs+10−9
@@ -15,23 +15,24 @@ strict h = do
1515 bs <- B.hGetContents h
1616 rnf (T.decodeUtf8 bs) `seq` return ()
1717
18−strict_ h = do
19− bs <- B.hGetContents h
20− rnf (T.decodeUtf8' bs) `seq` return ()
21−
2218strict_len h = do
2319 bs <- B.hGetContents h
24− print . T.length . T.init . T.decodeUtf8 $ bs
20+ print . T.length . T.decodeUtf8 $ bs
2521
26−strict__len h = do
22+strict_init_len h = do
2723 bs <- B.hGetContents h
28− print . T.length . T.init . T.decodeUtf8' $ bs
24+ print . T.length . T.init . T.decodeUtf8 $ bs
2925
3026strict_io h = do
3127 hSetEncoding h utf8
3228 t <- T.hGetContents h
3329 rnf t `seq` return ()
3430
31+strict_len_io h = do
32+ hSetEncoding h utf8
33+ t <- T.hGetContents h
34+ print (T.length t)
35+
3536lazy h = do
3637 bs <- BL.hGetContents h
3738 rnf (TL.decodeUtf8 bs) `seq` return ()
@@ -51,10 +52,10 @@ main = do
5152 h <- openFile name ReadMode
5253 case kind of
5354 "strict" -> strict h
54− "strict_" -> strict_ h
55− "strict__len" -> strict__len h
5655 "strict_len" -> strict_len h
56+ "strict_init_len" -> strict_init_len h
5757 "strict_io" -> strict_io h
58+ "strict_len_io" -> strict_len_io h
5859 "lazy" -> lazy h
5960 "lazy_io" -> lazy_io h
6061 "string" -> string h