diff options
| author | Max Bolingbroke <batterseapower@hotmail.com> | 2013-03-24 13:04:58 +0000 |
|---|---|---|
| committer | Max Bolingbroke <batterseapower@hotmail.com> | 2013-03-24 14:18:45 +0000 |
| commit | 90d1d92ce6ac7d34111f4b6c583a1dbc77fb90a7 (patch) | |
| tree | ba6c91728ffe154d09c48b1f72fe8f90c745117b | |
| parent | 197125fef19f3459059db5a0a323af63bff7adcf (diff) | |
| download | haskell-90d1d92ce6ac7d34111f4b6c583a1dbc77fb90a7.tar.gz | |
Don't just fail if hGetBufSome is used on a non-FD: fall back on the slow path instead
| -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 |
