aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormichaelt <what_is_it_to_do_anything@yahoo.com>2013-11-26 13:55:12 -0500
committermichaelt <what_is_it_to_do_anything@yahoo.com>2013-11-26 13:55:12 -0500
commit8853a440e37523bae8cb46827d0d2d356bad5c46 (patch)
tree59c97214d559e12f3a33e5840f2d709986d5cef0
parent5e3f5409333cf06f79489169195e5cd7031ac4bd (diff)
downloadtext-pipes-8853a440e37523bae8cb46827d0d2d356bad5c46.tar.gz
text-pipes-8853a440e37523bae8cb46827d0d2d356bad5c46.tar.zst
text-pipes-8853a440e37523bae8cb46827d0d2d356bad5c46.zip
fromHandle further optimized
-rw-r--r--Pipes/Text.hs10
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
226fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () 226fromHandle :: MonadIO m => IO.Handle -> Producer' Text m ()
227#if MIN_VERSION_text(0,11,4) 227#if MIN_VERSION_text(0,11,4)
228fromHandle h = PB.fromHandle h >-> pipeDecodeUtf8 228fromHandle 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
237fromHandle h = go where 241fromHandle h = go where
238 go = do txt <- liftIO (T.hGetChunk h) 242 go = do txt <- liftIO (T.hGetChunk h)