on master help sign in
Get rid of old lazy UTF-8 function
d952f7bBryan O'Sullivan
Data/Text/Lazy/Encoding.hs+5−17
@@ -20,14 +20,12 @@ module Data.Text.Lazy.Encoding
20 -- * Decoding ByteStrings to Text
20 -- * Decoding ByteStrings to Text
21 decodeASCII
21 decodeASCII
22 , decodeUtf8
22 , decodeUtf8
23− , decodeUtf8'
24 , decodeUtf16LE
23 , decodeUtf16LE
25 , decodeUtf16BE
24 , decodeUtf16BE
26 , decodeUtf32LE
25 , decodeUtf32LE
27 , decodeUtf32BE
26 , decodeUtf32BE
28 -- ** Controllable error handling
27 -- ** Controllable error handling
29 , decodeUtf8With
28 , decodeUtf8With
30− , decodeUtf8With'
31 , decodeUtf16LEWith
29 , decodeUtf16LEWith
32 , decodeUtf16BEWith
30 , decodeUtf16BEWith
33 , decodeUtf32LEWith
31 , decodeUtf32LEWith
@@ -60,17 +58,7 @@ decodeASCII bs = foldr (chunk . TE.decodeASCII) empty (B.toChunks bs)
60
58
61-- | Decode a 'ByteString' containing UTF-8 encoded text.
59-- | Decode a 'ByteString' containing UTF-8 encoded text.
62decodeUtf8With :: OnDecodeError -> B.ByteString -> Text
60decodeUtf8With :: OnDecodeError -> B.ByteString -> Text
63−decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
61+decodeUtf8With onErr bs0 = fast bs0
64−{-# INLINE decodeUtf8With #-}
65−
66−-- | Decode a 'ByteString' containing UTF-8 encoded text.
67−decodeUtf8 :: B.ByteString -> Text
68−decodeUtf8 = decodeUtf8With strictDecode
69−{-# INLINE decodeUtf8 #-}
70−
71−-- | Decode a 'ByteString' containing UTF-8 encoded text.
72−decodeUtf8With' :: OnDecodeError -> B.ByteString -> Text
73−decodeUtf8With' onErr bs0 = fast bs0
74 where
62 where
75 decode = TE.decodeUtf8With onErr
63 decode = TE.decodeUtf8With onErr
76 fast (B.Chunk p ps) | isComplete p = chunk (decode p) (fast ps)
64 fast (B.Chunk p ps) | isComplete p = chunk (decode p) (fast ps)
@@ -104,12 +92,12 @@ decodeUtf8With' onErr bs0 = fast bs0
104 where len = S.length bs
92 where len = S.length bs
105 ix n = S.unsafeIndex bs (len-n)
93 ix n = S.unsafeIndex bs (len-n)
106 desc = "Data.Text.Lazy.Encoding.decodeUtf8With: Invalid UTF-8 stream"
94 desc = "Data.Text.Lazy.Encoding.decodeUtf8With: Invalid UTF-8 stream"
107−{-# INLINE[0] decodeUtf8With' #-}
95+{-# INLINE[0] decodeUtf8With #-}
108
96
109-- | Decode a 'ByteString' containing UTF-8 encoded text.
97-- | Decode a 'ByteString' containing UTF-8 encoded text.
110−decodeUtf8' :: B.ByteString -> Text
98+decodeUtf8 :: B.ByteString -> Text
111−decodeUtf8' = decodeUtf8With' strictDecode
99+decodeUtf8 = decodeUtf8With strictDecode
112−{-# INLINE[0] decodeUtf8' #-}
100+{-# INLINE[0] decodeUtf8 #-}
113
101
114-- This rule seems to cause performance loss.
102-- This rule seems to cause performance loss.
115{- RULES "LAZY STREAM stream/decodeUtf8' fusion" [1]
103{- RULES "LAZY STREAM stream/decodeUtf8' fusion" [1]
tests/benchmarks/DecodeUtf8.hs−15
@@ -37,26 +37,14 @@ lazy h = do
37 bs <- BL.hGetContents h
37 bs <- BL.hGetContents h
38 rnf (TL.decodeUtf8 bs) `seq` return ()
38 rnf (TL.decodeUtf8 bs) `seq` return ()
39
39
40−lazy_ h = do
41− bs <- BL.hGetContents h
42− rnf (TL.decodeUtf8' bs) `seq` return ()
43−
44lazy_len h = do
40lazy_len h = do
45 bs <- BL.hGetContents h
41 bs <- BL.hGetContents h
46 print . TL.length . TL.decodeUtf8 $ bs
42 print . TL.length . TL.decodeUtf8 $ bs
47
43
48−lazy__len h = do
49− bs <- BL.hGetContents h
50− print . TL.length . TL.decodeUtf8' $ bs
51−
52lazy_init_len h = do
44lazy_init_len h = do
53 bs <- BL.hGetContents h
45 bs <- BL.hGetContents h
54 print . TL.length . TL.init . TL.decodeUtf8 $ bs
46 print . TL.length . TL.init . TL.decodeUtf8 $ bs
55
47
56−lazy__init_len h = do
57− bs <- BL.hGetContents h
58− print . TL.length . TL.init . TL.decodeUtf8' $ bs
59−
60lazy_io h = do
48lazy_io h = do
61 hSetEncoding h utf8
49 hSetEncoding h utf8
62 t <- TL.hGetContents h
50 t <- TL.hGetContents h
@@ -109,9 +97,6 @@ main = do
109 "lazy" -> lazy h
97 "lazy" -> lazy h
110 "lazy_len" -> lazy_len h
98 "lazy_len" -> lazy_len h
111 "lazy_init_len" -> lazy_init_len h
99 "lazy_init_len" -> lazy_init_len h
112− "lazy__init_len" -> lazy__init_len h
113− "lazy_" -> lazy_ h
114− "lazy__len" -> lazy__len h
115 "lazy_io" -> lazy_io h
100 "lazy_io" -> lazy_io h
116 "lazy_len_io" -> lazy_len_io h
101 "lazy_len_io" -> lazy_len_io h
117 "string" -> string h
102 "string" -> string h