diff options
Diffstat (limited to 'Pipes/Text.hs')
-rw-r--r-- | Pipes/Text.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs index 3d119fe..a5859a3 100644 --- a/Pipes/Text.hs +++ b/Pipes/Text.hs | |||
@@ -225,14 +225,18 @@ stdin = fromHandle IO.stdin | |||
225 | 225 | ||
226 | fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () | 226 | fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () |
227 | #if MIN_VERSION_text(0,11,4) | 227 | #if MIN_VERSION_text(0,11,4) |
228 | fromHandle h = PB.fromHandle h >-> pipeDecodeUtf8 | 228 | fromHandle h = go TE.streamDecodeUtf8 where |
229 | {-# INLINABLE fromHandle#-} | 229 | act = B.hGetSome h defaultChunkSize |
230 | go dec = do chunk <- liftIO act | ||
231 | case dec chunk of | ||
232 | TE.Some text _ dec' -> do yield text | ||
233 | unless (B.null chunk) (go dec') | ||
234 | {-# INLINE fromHandle#-} | ||
230 | -- bytestring fromHandle + streamDecodeUtf8 is 3 times as fast as | 235 | -- bytestring fromHandle + streamDecodeUtf8 is 3 times as fast as |
231 | -- the dedicated Text IO function 'hGetChunk' ; | 236 | -- the dedicated Text IO function 'hGetChunk' ; |
232 | -- this way "runEffect $ PT.fromHandle hIn >-> PT.toHandle hOut" | 237 | -- this way "runEffect $ PT.fromHandle hIn >-> PT.toHandle hOut" |
233 | -- runs the same as the conduit equivalent, only slightly slower | 238 | -- runs the same as the conduit equivalent, only slightly slower |
234 | -- than "runEffect $ PB.fromHandle hIn >-> PB.toHandle hOut" | 239 | -- than "runEffect $ PB.fromHandle hIn >-> PB.toHandle hOut" |
235 | |||
236 | #else | 240 | #else |
237 | fromHandle h = go where | 241 | fromHandle h = go where |
238 | go = do txt <- liftIO (T.hGetChunk h) | 242 | go = do txt <- liftIO (T.hGetChunk h) |