on master help sign in
Add a rewrite rule for fusion

--HG-- extra : convert_revision : ad8873d09eb7c252ca36bdcfe1b56ad0ad473bca

commitbe3f9d831e37a5430818fac64bb1e12663f95ad7 authorBryan O'Sullivan <bos@serpentine.com> dateThu 14 Oct 2010, 22:58 (16 years ago) parent2189300
2 files changed+16−3
Data/Text/Encoding.hs+6−3 tests/benchmarks/DecodeUtf8.hs+10
Data/Text/Encoding.hs+6−3
@@ -42,7 +42,7 @@ module Data.Text.Encoding
4242 , encodeUtf32LE
4343 , encodeUtf32BE
4444 ) where
45−
45+
4646import Data.Bits ((.&.))
4747import Data.ByteString as B
4848import Data.ByteString.Internal as B
@@ -110,12 +110,15 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
110110 w <- unsafeWrite arr n c
111111 go (n+w) (m+1)
112112 desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
113−{-# INLINE decodeUtf8With' #-}
113+{-# INLINE[0] decodeUtf8With' #-}
114114
115115-- | Decode a 'ByteString' containing UTF-8 encoded text.
116116decodeUtf8' :: ByteString -> Text
117117decodeUtf8' = 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 #-}
119122
120123-- | Encode text using UTF-8 encoding.
121124encodeUtf8 :: Text -> ByteString
tests/benchmarks/DecodeUtf8.hs+10
@@ -19,6 +19,14 @@ strict_ h = do
1919 bs <- B.hGetContents h
2020 rnf (T.decodeUtf8' bs) `seq` return ()
2121
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+
2230strict_io h = do
2331 hSetEncoding h utf8
2432 t <- T.hGetContents h
@@ -44,6 +52,8 @@ main = do
4452 case kind of
4553 "strict" -> strict h
4654 "strict_" -> strict_ h
55+ "strict__len" -> strict__len h
56+ "strict_len" -> strict_len h
4757 "strict_io" -> strict_io h
4858 "lazy" -> lazy h
4959 "lazy_io" -> lazy_io h