Skip to content

Commit

Permalink
Removed length checks for utf8 hPutStr
Browse files Browse the repository at this point in the history
  • Loading branch information
BebeSparkelSparkel authored May 4, 2024
1 parent 28fe450 commit be8c01c
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/Data/Text/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be8c01c

Please sign in to comment.