aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormichaelt <what_is_it_to_do_anything@yahoo.com>2013-11-26 00:55:41 -0500
committermichaelt <what_is_it_to_do_anything@yahoo.com>2013-11-26 00:55:41 -0500
commit5e3f5409333cf06f79489169195e5cd7031ac4bd (patch)
tree873ed1b89e4874f6a719d79842450046f04e71f3
parentff38b9f029818b81f8e1c309f7eccc979ba5c346 (diff)
downloadtext-pipes-5e3f5409333cf06f79489169195e5cd7031ac4bd.tar.gz
text-pipes-5e3f5409333cf06f79489169195e5cd7031ac4bd.tar.zst
text-pipes-5e3f5409333cf06f79489169195e5cd7031ac4bd.zip
scrap Text.hGetChunk for bytestring + streamDecodeUtf8, which is three times as fast
-rw-r--r--Pipes/Text.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs
index 4fc6c4a..3d119fe 100644
--- a/Pipes/Text.hs
+++ b/Pipes/Text.hs
@@ -165,6 +165,7 @@ import qualified Data.List as List
165import Foreign.C.Error (Errno(Errno), ePIPE) 165import Foreign.C.Error (Errno(Errno), ePIPE)
166import qualified GHC.IO.Exception as G 166import qualified GHC.IO.Exception as G
167import Pipes 167import Pipes
168import qualified Pipes.ByteString as PB
168import qualified Pipes.ByteString.Parse as PBP 169import qualified Pipes.ByteString.Parse as PBP
169import Pipes.Text.Parse ( 170import Pipes.Text.Parse (
170 nextChar, drawChar, unDrawChar, peekChar, isEndOfChars ) 171 nextChar, drawChar, unDrawChar, peekChar, isEndOfChars )
@@ -223,12 +224,22 @@ stdin = fromHandle IO.stdin
223-} 224-}
224 225
225fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () 226fromHandle :: MonadIO m => IO.Handle -> Producer' Text m ()
227#if MIN_VERSION_text(0,11,4)
228fromHandle h = PB.fromHandle h >-> pipeDecodeUtf8
229{-# INLINABLE fromHandle#-}
230-- bytestring fromHandle + streamDecodeUtf8 is 3 times as fast as
231-- the dedicated Text IO function 'hGetChunk' ;
232-- this way "runEffect $ PT.fromHandle hIn >-> PT.toHandle hOut"
233-- runs the same as the conduit equivalent, only slightly slower
234-- than "runEffect $ PB.fromHandle hIn >-> PB.toHandle hOut"
235
236#else
226fromHandle h = go where 237fromHandle h = go where
227 go = do txt <- liftIO (T.hGetChunk h) 238 go = do txt <- liftIO (T.hGetChunk h)
228 unless (T.null txt) $ do yield txt 239 unless (T.null txt) $ do yield txt
229 go 240 go
230{-# INLINABLE fromHandle#-} 241{-# INLINABLE fromHandle#-}
231 242#endif
232{-| Stream text from a file using Pipes.Safe 243{-| Stream text from a file using Pipes.Safe
233 244
234>>> runSafeT $ runEffect $ Text.readFile "hello.hs" >-> Text.map toUpper >-> hoist lift Text.stdout 245>>> runSafeT $ runEffect $ Text.readFile "hello.hs" >-> Text.map toUpper >-> hoist lift Text.stdout