This is an archive of the discontinued LLVM Phabricator instance.

Support: Skip buffering buffer_unique_ostream's owned stream

Authored by dexonsmith on Sep 23 2021, 3:05 PM.



Change buffer_unique_ostream's constructor to call
raw_ostream::SetUnbuffered() on its owned stream. Otherwise,
buffer_unique_ostream's destructor could cause the owned stream to
temporarily allocate a buffer only to be immediately flushed.

Also add some tests for buffer_ostream and buffer_unique_ostream. Use
the same naming scheme as other raw_ostream-related tests (e.g.,
raw_ostreamTest for the fixture, raw_ostream_test.cpp for the

(I considered changing buffer_ostream in the same way (calling
SetUnbuffered on the referenced stream), but that seemed like overreach
since the client may have more things to write.)

(I considered merging buffer_ostream and buffer_unique_ostream into a
single class (with a raw_ostream& and a std::unique_ptr that is only
sometimes used), but that makes the class bigger and the small amount of
code deduplication seems uncompelling.)

Diff Detail

Event Timeline

dexonsmith created this revision.Sep 23 2021, 3:05 PM
dexonsmith requested review of this revision.Sep 23 2021, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2021, 3:05 PM
dexonsmith added a reviewer: steven_wu.

(Forgot to run clang-format; done now)

This revision is now accepted and ready to land.Sep 23 2021, 4:54 PM
This revision was landed with ongoing or failed builds.Oct 22 2021, 4:26 PM
This revision was automatically updated to reflect the committed changes.