Commits

Bryan O'Sullivan committed 8fbfde0

Add a rewrite rule for fusion

  • Participants
  • Parent commits fe6879f

Comments (0)

Files changed (2)

File Data/Text/Encoding.hs

     , encodeUtf32LE
     , encodeUtf32BE
     ) where
-    
+
 import Data.Bits ((.&.))
 import Data.ByteString as B
 import Data.ByteString.Internal as B
                            w <- unsafeWrite arr n c
                            go (n+w) (m+1)
   desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
-{-# INLINE decodeUtf8With' #-}
+{-# INLINE[0] decodeUtf8With' #-}
 
 -- | Decode a 'ByteString' containing UTF-8 encoded text.
 decodeUtf8' :: ByteString -> Text
 decodeUtf8' = decodeUtf8With' strictDecode
-{-# INLINE decodeUtf8' #-}
+{-# INLINE[0] decodeUtf8' #-}
+
+{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
+    forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
 
 -- | Encode text using UTF-8 encoding.
 encodeUtf8 :: Text -> ByteString

File tests/benchmarks/DecodeUtf8.hs

   bs <- B.hGetContents h
   rnf (T.decodeUtf8' bs) `seq` return ()
 
+strict_len h = do
+  bs <- B.hGetContents h
+  print . T.length . T.init . T.decodeUtf8 $ bs
+
+strict__len h = do
+  bs <- B.hGetContents h
+  print . T.length . T.init . T.decodeUtf8' $ bs
+
 strict_io h = do
   hSetEncoding h utf8
   t <- T.hGetContents h
   case kind of
     "strict" -> strict h
     "strict_" -> strict_ h
+    "strict__len" -> strict__len h
+    "strict_len" -> strict_len h
     "strict_io" -> strict_io h
     "lazy" -> lazy h
     "lazy_io" -> lazy_io h