-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate UTF-8 hPutStr
to standard hPutStr
#589
Integrate UTF-8 hPutStr
to standard hPutStr
#589
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inspecting the textEncodingName
of TextEncoding
like you did seems like the right way.
47987f8
to
603dffc
Compare
2a5714e
to
e1068f1
Compare
I merged with master (adapting to changes from #600 which moved the logic of |
@Lysxia shall we drop GHC 8.2 CI job? |
src/Data/Text/Internal/IO.hs
Outdated
-- | Write a string to a handle, followed by a newline. | ||
hPutStrLn :: Handle -> Text -> IO () | ||
hPutStrLn h t = hPutStreamOrUtf8 h (streamLn t) (Just putUtf8) | ||
where putUtf8 = hPutBuilder h (encodeUtf8Builder t <> charUtf8 '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not B.hPutStrLn h (encodeUtf8 t)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have to be B.hPutStrLn h (encodeUtf8 (t <> '\n'))
. I couldn't find another way to append the '\n'
at the end in constant time. Open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect B.hPutStrLn
to append '\n'
on its own, am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't see your Ln
. There is no B.hPutStrLn
... right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hPutStrLn :: Handle -> ByteString -> IO ()
hPutStrLn h ps = hPut h ps >> hPut h (L.singleton 0x0a)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the B.hPutStrLn implementation since it breaks the atomic printing that was just implemented for strict hPustStrLn in #600
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that non-100%-atomicity of B.hPutStrLn
is for bytestring
to resolve, not for us. But does hPutBuilder
guarantee atomic printing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
B.hPutBuilder
does if it can fit in the buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reopened haskell/bytestring#200 and added a comment.
Thanks a ton! |
hPutStr
to standard hPutStr
Data.Text.IO.Utf8.hPutStr
was implemented in #503 and has much better performance thanData.Text.IO.hPutStr
when the encoding is"UTF-8"
and the neline isLF
, so I added it.Question: Is there a faster way to check for the encoding without checking for string equality?