on master help sign in
Add a rewrite rule for fusion
be3f9d8Bryan O'Sullivan
Data/Text/Encoding.hs+6−3
@@ -42,7 +42,7 @@ module Data.Text.Encoding
42 , encodeUtf32LE
42 , encodeUtf32LE
43 , encodeUtf32BE
43 , encodeUtf32BE
44 ) where
44 ) where
45−
45+
46import Data.Bits ((.&.))
46import Data.Bits ((.&.))
47import Data.ByteString as B
47import Data.ByteString as B
48import Data.ByteString.Internal as B
48import Data.ByteString.Internal as B
@@ -110,12 +110,15 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
110 w <- unsafeWrite arr n c
110 w <- unsafeWrite arr n c
111 go (n+w) (m+1)
111 go (n+w) (m+1)
112 desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
112 desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
113−{-# INLINE decodeUtf8With' #-}
113+{-# INLINE[0] decodeUtf8With' #-}
114
114
115-- | Decode a 'ByteString' containing UTF-8 encoded text.
115-- | Decode a 'ByteString' containing UTF-8 encoded text.
116decodeUtf8' :: ByteString -> Text
116decodeUtf8' :: ByteString -> Text
117decodeUtf8' = decodeUtf8With' strictDecode
117decodeUtf8' = decodeUtf8With' strictDecode
118−{-# INLINE decodeUtf8' #-}
118+{-# INLINE[0] decodeUtf8' #-}
119+
120+{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
121+ forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
119
122
120-- | Encode text using UTF-8 encoding.
123-- | Encode text using UTF-8 encoding.
121encodeUtf8 :: Text -> ByteString
124encodeUtf8 :: Text -> ByteString
tests/benchmarks/DecodeUtf8.hs+10
@@ -19,6 +19,14 @@ strict_ h = do
19 bs <- B.hGetContents h
19 bs <- B.hGetContents h
20 rnf (T.decodeUtf8' bs) `seq` return ()
20 rnf (T.decodeUtf8' bs) `seq` return ()
21
21
22+strict_len h = do
23+ bs <- B.hGetContents h
24+ print . T.length . T.init . T.decodeUtf8 $ bs
25+
26+strict__len h = do
27+ bs <- B.hGetContents h
28+ print . T.length . T.init . T.decodeUtf8' $ bs
29+
22strict_io h = do
30strict_io h = do
23 hSetEncoding h utf8
31 hSetEncoding h utf8
24 t <- T.hGetContents h
32 t <- T.hGetContents h
@@ -44,6 +52,8 @@ main = do
44 case kind of
52 case kind of
45 "strict" -> strict h
53 "strict" -> strict h
46 "strict_" -> strict_ h
54 "strict_" -> strict_ h
55+ "strict__len" -> strict__len h
56+ "strict_len" -> strict_len h
47 "strict_io" -> strict_io h
57 "strict_io" -> strict_io h
48 "lazy" -> lazy h
58 "lazy" -> lazy h
49 "lazy_io" -> lazy_io h
59 "lazy_io" -> lazy_io h