on master help sign in
Shuffle around buffer management
5ac1d3aBryan O'Sullivan
Data/Text/IO.hs+5−4
@@ -97,15 +97,16 @@ hGetContents h = do
97 return (hh'{haType=ClosedHandle},T.concat ts)
97 return (hh'{haType=ClosedHandle},T.concat ts)
98 where
98 where
99 readAll hh@Handle__{..} = do
99 readAll hh@Handle__{..} = do
100− buf <- readIORef haCharBuffer
101 let readChunks = do
100 let readChunks = do
102− t <- readChunk hh buf
101+ t <- readChunk hh =<< readIORef haCharBuffer
103− (hh',ts) <- readAll hh
102+ (hh',ts) <- readChunks
104 return (hh', t:ts)
103 return (hh', t:ts)
105 readChunks `catch` \e -> do
104 readChunks `catch` \e -> do
106 (hh', _) <- hClose_help hh
105 (hh', _) <- hClose_help hh
107 if isEOFError e
106 if isEOFError e
107+ then do
108+ buf <- readIORef haCharBuffer
108− then return $ if isEmptyBuffer buf
109+ return $ if isEmptyBuffer buf
109 then (hh', [])
110 then (hh', [])
110 else (hh', [T.singleton '\r'])
111 else (hh', [T.singleton '\r'])
111 else throw (augmentIOError e "hGetContents" h)
112 else throw (augmentIOError e "hGetContents" h)