ostream::operator<<() and sputn()

Jonathan Wakely jwakely.gcc@gmail.com
Tue Jan 11 01:09:03 GMT 2022


On Mon, 10 Jan 2022 at 23:18, Lewis Hyatt wrote:
> Thanks a lot for circling back to this. I feel like your change is a
> pure improvement with little downside, so it would be great to have
> it. Let me know please if I should do anything more there.

Leave it with me.

> To me, the whole situation with sputn() is just unfortunate, because I
> think it should not have been specified to always make the virtual
> call to xsputn(), but rather only make it if needed. Then everything
> would work as well as possible. Like after this change to the
> single-char overload, a similar unexpected performance issue will
> affect something like:  cout << "a"  compared to cout << 'a', where
> now the former will make a virtual call every time and the latter
> won't. libstdc++ could handle the char* overload case as well, but
> then it still would not be permitted to handle a string or
> string_view, so at some level the standard specification is the
> constraint... Seems unlikely it will change though, so I think it
> means that avoiding sputn() wherever permitted will always be an
> avenue towards improving performance.

I think the standard is overspecified, and changing it makes sense. It will
take some time though.


More information about the Libstdc++ mailing list