gcc/libstdc++-v3/include
Jonathan Wakely e4fe6dba90 libstdc++: Optimize std::ostream inserters for single characters
On the libsdc++ mailing list Lewis Hyatt pointed out the performance
overhead of using sputn in stream inserters, rather than writing
directly to the streambuf's put area:
https://gcc.gnu.org/pipermail/libstdc++/2021-July/052877.html

As Lewis noted, the standard explicitly requires a call to sputn for
inserting a std::basic_string_view or std::basic_string.  But for
inserting single characters or null-terminated strings it is more vague,
and so we can improve performance by not using the __ostream_insert
function.

This is a minimal change that avoids __ostream_insert for single
characters. We can use the unformatted basic_ostream::put(charT)
function when we don't need the additional effects of a formatted output
function (i.e. padding and resetting the width). The put function will
insert into the buffer if possible, and only make a virtual call (to
overflow) if the buffer is full.

We could also avoid sputn when inserting null-terminated character
strings, but that would require using a new function for inserting
null-terminated strings, so the existing code using sputn is still used
for basic_string and basic_string_view. My preference is to leave that
for now, and try to improve the standard. We could either remove the
requirement to call sputn, or allow sputn to write directly to the
buffer instead of calling xsputn.

libstdc++-v3/ChangeLog:

	* include/std/ostream (operator<<(basic_ostream&, charT)):
	Use unformatted input if no padding is needed.
	(operator<<(basic_ostream<char>&, char)): Likewise.
2022-01-11 13:28:46 +00:00
..
backward Update copyright years. 2022-01-03 10:42:10 +01:00
bits libstdc++: Make std::variant work with Clang in C++20 mode [PR103891] 2022-01-11 13:22:35 +00:00
c Update copyright years. 2022-01-03 10:42:10 +01:00
c_compatibility Update copyright years. 2022-01-03 10:42:10 +01:00
c_global Update copyright years. 2022-01-03 10:42:10 +01:00
c_std Update copyright years. 2022-01-03 10:42:10 +01:00
debug Update copyright years. 2022-01-03 10:42:10 +01:00
decimal Update copyright years. 2022-01-03 10:42:10 +01:00
experimental Update copyright years. 2022-01-03 10:42:10 +01:00
ext Update copyright years. 2022-01-03 10:42:10 +01:00
parallel Update copyright years. 2022-01-03 10:42:10 +01:00
precompiled Update copyright years. 2022-01-03 10:42:10 +01:00
pstl
std libstdc++: Optimize std::ostream inserters for single characters 2022-01-11 13:28:46 +00:00
tr1 Update copyright years. 2022-01-03 10:42:10 +01:00
tr2 Update copyright years. 2022-01-03 10:42:10 +01:00
Makefile.am Update copyright years. 2022-01-03 10:42:10 +01:00
Makefile.in libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00