Skip to content

[libc++] __vprint_unicode_posix() has unnecessary call to fflush() #70142

Open
@dimztimz

Description

@dimztimz

__vprint_unicode_posix(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl, bool __is_terminal) {
// TODO PRINT Should flush errors throw too?
if (__is_terminal)
std::fflush(__stream);
__print::__vprint_nonunicode(__stream, __fmt, __args, __write_nl);
}

In this function the following two lines are not necessary and introduce performance pessimization.

if (__is_terminal)
std::fflush(__stream);

Additionally, if you read the standard carefully http://www.eel.is/c++draft/print.fun#7.sentence-4 It says:

If the native Unicode API is used, the function flushes stream before writing out.

Although POSIX offers a way to query if a C stream goes to terminal or not, it does not have native Unicode API, so such API is never used, and flushing is not needed. A consequence of this is that on POSIX querying the C stream is not needed at all and it is another performance pessimization. The call to __is_terminal() is not needed here.

# ifndef _WIN32
__print::__vprint_unicode_posix(__stream, __fmt, __args, __write_nl, __print::__is_terminal(__stream));

Metadata

Metadata

Labels

formatC++20 std::format or std::print, and anything related to themlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions