@@ -40,12 +40,11 @@ import GHC.IO.Buffer (Buffer(..), BufferState(..), CharBuffer, RawCharBuffer,
40
40
bufferAdjustL , bufferElems , charSize , emptyBuffer ,
41
41
isEmptyBuffer , newCharBuffer , readCharBuf , withRawBuffer ,
42
42
writeCharBuf )
43
- import GHC.IO.Encoding (utf8 )
44
43
import GHC.IO.Handle.Internals (ioe_EOF , readTextDevice , wantReadableHandle_ ,
45
44
wantWritableHandle )
46
45
import GHC.IO.Handle.Text (commitBuffer' )
47
46
import GHC.IO.Handle.Types (BufferList (.. ), BufferMode (.. ), Handle__ (.. ), Newline (.. ))
48
- import System.IO (Handle , hPutChar )
47
+ import System.IO (Handle , hPutChar , utf8 )
49
48
import System.IO.Error (isEOFError )
50
49
import qualified Data.Text as T
51
50
@@ -204,6 +203,10 @@ hPutStreamOrUtf8 h str mPutUtf8 = do
204
203
(BlockBuffering _, buf) -> writeBlocks (nl == CRLF ) h buf str
205
204
206
205
where
206
+ -- If the encoding is UTF-8, it's most likely pointer-equal to
207
+ -- 'System.IO.utf8', letting us avoid a String comparison.
208
+ -- If it is somehow UTF-8 but not pointer-equal to 'utf8',
209
+ -- we will just take a slower branch, but the result is still correct.
207
210
eqUTF8 = maybe False (\ enc -> isTrue# (reallyUnsafePtrEquality# utf8 enc)) . haCodec
208
211
{-# INLINE hPutStreamOrUtf8 #-}
209
212
0 commit comments