Fix: hPutBuf issues unnecessary empty write syscalls for large writes (#13246)
authorNiklas Hamb├╝chen <mail@nh2.me>
Sun, 12 Feb 2017 00:24:30 +0000 (19:24 -0500)
committerBen Gamari <ben@smart-cactus.org>
Sun, 12 Feb 2017 00:58:35 +0000 (19:58 -0500)
commit805db96544111bd548c9a32488a9c97996cc2b49
tree6a052e5a3b9424e9f2ae3013dd21a6843ed45d49
parent4e2e9b7324e253295613fe868a281e1801e05d10
Fix: hPutBuf issues unnecessary empty write syscalls for large writes (#13246)

Until now, any `hPutBuf` that wrote `>= the handle buffer size` would
trigger an unnecessary `write("")` system call before the actual write
system call.

This is fixed by making sure that we never flush an empty handle buffer:
Only flush `when (w > 0)`.

Reviewers: simonmar, austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D3119
libraries/base/GHC/IO/Handle/Text.hs