gcc/libstdc++-v3/include/std
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
..
algorithm Update copyright years. 2022-01-03 10:42:10 +01:00
any Update copyright years. 2022-01-03 10:42:10 +01:00
array Update copyright years. 2022-01-03 10:42:10 +01:00
atomic Update copyright years. 2022-01-03 10:42:10 +01:00
barrier Update copyright years. 2022-01-03 10:42:10 +01:00
bit Update copyright years. 2022-01-03 10:42:10 +01:00
bitset Update copyright years. 2022-01-03 10:42:10 +01:00
charconv libstdc++: Do not use std::isdigit in <charconv> [PR103911] 2022-01-06 14:56:12 +00:00
chrono Update copyright years. 2022-01-03 10:42:10 +01:00
codecvt Update copyright years. 2022-01-03 10:42:10 +01:00
complex Update copyright years. 2022-01-03 10:42:10 +01:00
concepts Update copyright years. 2022-01-03 10:42:10 +01:00
condition_variable Update copyright years. 2022-01-03 10:42:10 +01:00
coroutine Update copyright years. 2022-01-03 10:42:10 +01:00
deque Update copyright years. 2022-01-03 10:42:10 +01:00
execution Update copyright years. 2022-01-03 10:42:10 +01:00
filesystem Update copyright years. 2022-01-03 10:42:10 +01:00
forward_list Update copyright years. 2022-01-03 10:42:10 +01:00
fstream Update copyright years. 2022-01-03 10:42:10 +01:00
functional Update copyright years. 2022-01-03 10:42:10 +01:00
future Update copyright years. 2022-01-03 10:42:10 +01:00
iomanip Update copyright years. 2022-01-03 10:42:10 +01:00
ios Update copyright years. 2022-01-03 10:42:10 +01:00
iosfwd Update copyright years. 2022-01-03 10:42:10 +01:00
iostream Update copyright years. 2022-01-03 10:42:10 +01:00
istream Update copyright years. 2022-01-03 10:42:10 +01:00
iterator Update copyright years. 2022-01-03 10:42:10 +01:00
latch Update copyright years. 2022-01-03 10:42:10 +01:00
limits Update copyright years. 2022-01-03 10:42:10 +01:00
list Update copyright years. 2022-01-03 10:42:10 +01:00
locale Update copyright years. 2022-01-03 10:42:10 +01:00
map Update copyright years. 2022-01-03 10:42:10 +01:00
memory Update copyright years. 2022-01-03 10:42:10 +01:00
memory_resource Update copyright years. 2022-01-03 10:42:10 +01:00
mutex Update copyright years. 2022-01-03 10:42:10 +01:00
numbers Update copyright years. 2022-01-03 10:42:10 +01:00
numeric Update copyright years. 2022-01-03 10:42:10 +01:00
optional Update copyright years. 2022-01-03 10:42:10 +01:00
ostream libstdc++: Optimize std::ostream inserters for single characters 2022-01-11 13:28:46 +00:00
queue Update copyright years. 2022-01-03 10:42:10 +01:00
random Update copyright years. 2022-01-03 10:42:10 +01:00
ranges Update copyright years. 2022-01-03 10:42:10 +01:00
ratio Update copyright years. 2022-01-03 10:42:10 +01:00
regex Update copyright years. 2022-01-03 10:42:10 +01:00
scoped_allocator Update copyright years. 2022-01-03 10:42:10 +01:00
semaphore Update copyright years. 2022-01-03 10:42:10 +01:00
set Update copyright years. 2022-01-03 10:42:10 +01:00
shared_mutex Update copyright years. 2022-01-03 10:42:10 +01:00
source_location Update copyright years. 2022-01-03 10:42:10 +01:00
span Update copyright years. 2022-01-03 10:42:10 +01:00
spanstream libstdc++: Implement std::spanstream for C++23 2021-11-13 11:45:31 +00:00
sstream Update copyright years. 2022-01-03 10:42:10 +01:00
stack Update copyright years. 2022-01-03 10:42:10 +01:00
stdexcept Update copyright years. 2022-01-03 10:42:10 +01:00
stop_token Update copyright years. 2022-01-03 10:42:10 +01:00
streambuf Update copyright years. 2022-01-03 10:42:10 +01:00
string Update copyright years. 2022-01-03 10:42:10 +01:00
string_view Update copyright years. 2022-01-03 10:42:10 +01:00
syncstream Update copyright years. 2022-01-03 10:42:10 +01:00
system_error Update copyright years. 2022-01-03 10:42:10 +01:00
thread Update copyright years. 2022-01-03 10:42:10 +01:00
tuple Update copyright years. 2022-01-03 10:42:10 +01:00
type_traits Update copyright years. 2022-01-03 10:42:10 +01:00
typeindex Update copyright years. 2022-01-03 10:42:10 +01:00
unordered_map Update copyright years. 2022-01-03 10:42:10 +01:00
unordered_set Update copyright years. 2022-01-03 10:42:10 +01:00
utility Update copyright years. 2022-01-03 10:42:10 +01:00
valarray Update copyright years. 2022-01-03 10:42:10 +01:00
variant libstdc++: Make std::variant work with Clang in C++20 mode [PR103891] 2022-01-11 13:22:35 +00:00
vector Update copyright years. 2022-01-03 10:42:10 +01:00
version libstdc++: Make std::variant work with Clang in C++20 mode [PR103891] 2022-01-11 13:22:35 +00:00