diff options
| -rw-r--r-- | libraries/base/GHC/IO/Handle/Text.hs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/libraries/base/GHC/IO/Handle/Text.hs b/libraries/base/GHC/IO/Handle/Text.hs index 3eedae65de..14587729c5 100644 --- a/libraries/base/GHC/IO/Handle/Text.hs +++ b/libraries/base/GHC/IO/Handle/Text.hs @@ -878,9 +878,9 @@ hGetBufSome h ptr count flushCharReadBuffer h_ buf@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_@Handle__{..} = - case cast haDevice of - Nothing -> error "not an FD" - Just fd -> fd +haFD :: Handle__ -> Maybe FD +haFD h_@Handle__{..} = cast haDevice -- | 'hGetBufNonBlocking' @hdl buf count@ reads data from the handle @hdl@ -- into the buffer @buf@ until either EOF is reached, or |
