diff --git a/src/Data/Text/IO.hs b/src/Data/Text/IO.hs index 5f469958..dc71b824 100644 --- a/src/Data/Text/IO.hs +++ b/src/Data/Text/IO.hs @@ -180,23 +180,18 @@ hPutStr :: Handle -> Text -> IO () -- This function is lifted almost verbatim from GHC.IO.Handle.Text. hPutStr h t = do (buffer_mode, nl, isUTF8) <- - wantWritableHandle "hPutStr" h $ \h_ -> do - bmode <- getSpareBuffer h_ - let isUTF8 = maybe False ((== "UTF-8") . textEncodingName) $ haCodec h_ - return (bmode, haOutputNL h_, isUTF8) - let l = T.length t - str = stream t + wantWritableHandle "hPutStr" h $ \h_ -> do + bmode <- getSpareBuffer h_ + let isUTF8 = maybe False ((== "UTF-8") . textEncodingName) $ haCodec h_ + return (bmode, haOutputNL h_, isUTF8) + let str = stream t case buffer_mode of - (NoBuffering, _) - | l > 5 && nl == LF && isUTF8 -> utf8Put - | otherwise -> hPutChars h str - _ | l > 80 && nl == LF && isUTF8 -> utf8Put - (LineBuffering, bufC) -> writeLines h nl bufC str + _ | nl == LF && isUTF8 -> B.hPutStr h $ encodeUtf8 t + (NoBuffering, _) -> hPutChars h str + (LineBuffering, bufC) -> writeLines h nl bufC str (BlockBuffering _, bufC) - | nl == CRLF -> writeBlocksCRLF h bufC str - | otherwise -> writeBlocksRaw h bufC str - - where utf8Put = B.hPutStr h $ encodeUtf8 t + | nl == CRLF -> writeBlocksCRLF h bufC str + | otherwise -> writeBlocksRaw h bufC str hPutChars :: Handle -> Stream Char -> IO () hPutChars h (Stream next0 s0 _len) = loop s0