[commit: base] master: Don't just fail if hGetBufSome is used on a non-FD: fall back on the slow path instead (ac90f31)
Max Bolingbroke
batterseapower at hotmail.com
Sun Mar 24 15:20:19 CET 2013
Repository : ssh://darcs.haskell.org//srv/darcs/packages/base
On branch : master
https://github.com/ghc/packages-base/commit/ac90f31026b86bb65ef1b89df249809be8419959
>---------------------------------------------------------------
commit ac90f31026b86bb65ef1b89df249809be8419959
Author: Max Bolingbroke <batterseapower at hotmail.com>
Date: Sun Mar 24 13:04:58 2013 +0000
Don't just fail if hGetBufSome is used on a non-FD: fall back on the slow path instead
>---------------------------------------------------------------
GHC/IO/Handle/Text.hs | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/GHC/IO/Handle/Text.hs b/GHC/IO/Handle/Text.hs
index 3eedae6..1458772 100644
--- a/GHC/IO/Handle/Text.hs
+++ b/GHC/IO/Handle/Text.hs
@@ -878,9 +878,9 @@ hGetBufSome h ptr count
flushCharReadBuffer h_
buf at Buffer{ bufSize=sz } <- readIORef haByteBuffer
if isEmptyBuffer buf
- then if count > sz -- large read?
- then do RawIO.read (haFD h_) (castPtr ptr) count
- else do (r,buf') <- Buffered.fillReadBuffer haDevice buf
+ then case count > sz of -- large read? optimize it with a little special case:
+ True | Just fd <- haFD h_ -> do RawIO.read fd (castPtr ptr) count
+ _ -> do (r,buf') <- Buffered.fillReadBuffer haDevice buf
if r == 0
then return 0
else do writeIORef haByteBuffer buf'
@@ -892,11 +892,8 @@ hGetBufSome h ptr count
let count' = min count (bufferElems buf)
in bufReadNBNonEmpty h_ buf (castPtr ptr) 0 count'
-haFD :: Handle__ -> FD
-haFD h_ at Handle__{..} =
- case cast haDevice of
- Nothing -> error "not an FD"
- Just fd -> fd
+haFD :: Handle__ -> Maybe FD
+haFD h_ at Handle__{..} = cast haDevice
-- | 'hGetBufNonBlocking' @hdl buf count@ reads data from the handle @hdl@
-- into the buffer @buf@ until either EOF is reached, or
More information about the ghc-commits
mailing list