This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] Fix second half of libstdc++/6745
Jonathan Lennox wrote:
I'm pretty sure it can't happen with any of the standard streambuf classes
defined by the C++ standard, but it can easily happen for user-defined
streambuf classes.
As an example, consider test_buffer_1 from
libstdc++/testsuite/27_io/ostream_inserter_other.cc:
class test_buffer_1 : public std::streambuf
{
public:
test_buffer_1(const std::string& s) : str(s), it(str.begin()) { }
protected:
virtual int underflow() { return (it != str.end() ? *it : EOF); }
virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
private:
const std::string str;
std::string::const_iterator it;
};
__copy_streambufs will loop once without your patch, but s.length() times
with it, if stdin is a tty.
An actual practical example is something like Matt Austern's syncstream,
which is attached to PR 8071.
I want to study this in more detail but basically I believe you are
right: we have a performance
issue in such cases. Could you possibly work out a patch along the lines
which you suggested?
Not adding new public members to basic_filebuf, however...
Paolo