@@ -3815,6 +3815,10 @@ data WList = WCons !Word8 !WList | WNil
3816data EncodeState s = EncodeState s !WList
3816data EncodeState s = EncodeState s !WList
3818+-- More yield points improve performance, but I am not sure if they can cause
3819+-- too much code bloat or some trouble with fusion. So keeping only two yield
3820+-- points for now, one for the ascii chars (fast path) and one for all other
3821+-- paths (slow path).
3818{-# INLINE_NORMAL encodeUtf8 #-}
3822{-# INLINE_NORMAL encodeUtf8 #-}
3819encodeUtf8 :: Monad m => Stream m Char -> Stream m Word8
3823encodeUtf8 :: Monad m => Stream m Char -> Stream m Word8
3820encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
3824encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
@@ -3828,8 +3832,7 @@ encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
3828 case ord c of
3832 case ord c of
3830 | x <= 0x7F ->
3834 | x <= 0x7F ->
3832− (EncodeState s (WCons (fromIntegral x) WNil))
3835+ Yield (fromIntegral x) (EncodeState s WNil)
3833 | x <= 0x7FF -> Skip (EncodeState s (ord2 c))
3836 | x <= 0x7FF -> Skip (EncodeState s (ord2 c))
3834 | x <= 0xFFFF ->
3837 | x <= 0xFFFF ->
3835 if isSurrogate c
3838 if isSurrogate c