Skip to content

Commit

Permalink
Merge pull request #957 from mitchellwrosen/master
Browse files Browse the repository at this point in the history
tiny refactor: adjust placement of shared "I.writeIORef ref count'"
  • Loading branch information
kazu-yamamoto authored Dec 12, 2023
2 parents 711fa18 + a3fdf2a commit 8345744
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions warp/Network/Wai/Handler/Warp/Conduit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,23 @@ readISource (ISource src ref) = do
toSend = min count (S.length bs)
-- How many bytes will still remain to be sent downstream
count' = count - toSend
case () of
()
-- The expected count is greater than the size of the
-- chunk we just read. Send the entire chunk
-- downstream, and then loop on this function for the
-- next chunk.
| count' > 0 -> do
I.writeIORef ref count'
return bs

-- Some of the bytes in this chunk should not be sent
-- downstream. Split up the chunk into the sent and
-- not-sent parts, add the not-sent parts onto the new
-- source, and send the rest of the chunk downstream.
| otherwise -> do
let (x, y) = S.splitAt toSend bs
leftoverSource src y
assert (count' == 0) $ I.writeIORef ref count'
return x

I.writeIORef ref count'

if count' > 0 then
-- The expected count is greater than the size of the
-- chunk we just read. Send the entire chunk
-- downstream, and then loop on this function for the
-- next chunk.
return bs
else do
-- Some of the bytes in this chunk should not be sent
-- downstream. Split up the chunk into the sent and
-- not-sent parts, add the not-sent parts onto the new
-- source, and send the rest of the chunk downstream.
let (x, y) = S.splitAt toSend bs
leftoverSource src y
assert (count' == 0) $ return x

----------------------------------------------------------------

Expand Down

0 comments on commit 8345744

Please sign in to comment.