Title
stringbuf ctor inefficient
Status
cd1
Section
[string.streams]
Submitter
Martin Sebor

Created on 2006-02-23.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Change 27.7.1.1, p3 of the Working Draft, N1804, as follows:

explicit basic_stringbuf(const basic_string<charT,traits,Allocator>& str,
               ios_base::openmode which = ios_base::in | ios_base::out);

-3- Effects: Constructs an object of class basic_stringbuf, initializing the base class with basic_streambuf() (27.5.2.1), and initializing mode with which. Then calls str(s). copies the content of str into the basic_stringbuf underlying character sequence. If which & ios_base::out is true, initializes the output sequence such that pbase() points to the first underlying character, epptr() points one past the last underlying character, and pptr() is equal to epptr() if which & ios_base::ate is true, otherwise pptr() is equal to pbase(). If which & ios_base::in is true, initializes the input sequence such that eback() and gptr() point to the first underlying character and egptr() points one past the last underlying character.

Change the Effects clause of the str() in 27.7.1.2, p2 to read:

-2- Effects: Copies the contents of s into the basic_stringbuf underlying character sequence and initializes the input and output sequences according to mode. If mode & ios_base::out is true, initializes the output sequence such that pbase() points to the first underlying character, epptr() points one past the last underlying character, and pptr() is equal to epptr() if mode & ios_base::in is true, otherwise pptr() is equal to pbase(). If mode & ios_base::in is true, initializes the input sequence such that eback() and gptr() point to the first underlying character and egptr() points one past the last underlying character.

-3- Postconditions: If mode & ios_base::out is true, pbase() points to the first underlying character and (epptr() >= pbase() + s.size()) holds; in addition, if mode & ios_base::in is true, (pptr() == pbase() + s.data()) holds, otherwise (pptr() == pbase()) is true. If mode & ios_base::in is true, eback() points to the first underlying character, and (gptr() == eback()) and (egptr() == eback() + s.size()) hold.

Date: 2006-02-23.00:00:00

For better efficiency, the requirement on the stringbuf ctor that takes a string argument should be loosened up to let it set epptr() beyond just one past the last initialized character just like overflow() has been changed to be allowed to do (see issue 432). That way the first call to sputc() on an object won't necessarily cause a call to overflow. The corresponding change should be made to the string overload of the str() member function.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3065
2006-02-23 00:00:00admincreate