This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: basic_string<>::_M_mutate - patch



Ryszard wrote:
> First I made the same error. In this case of reserve the size()
> will be set in _M_mutate to capacity() (for example from 0 to 1000).
> A solution without a new implementation of reserve could be:
> 
>        if (__res_arg > this->capacity()) {
>          size_type __old_size = this->size();
>          _M_mutate(__old_size, 0, __res_arg - __old_size);
>          _M_rep()->_M_length = __old_size;
>        }

I see now.

> I think in reserve we must not terminate the string.

AFAIU it is permissible, but adds some (small?) overhead by
touching memory that does not otherwise need to be touched yet.  
Probably it would be better to generalize _M_clone to handle
this case, or (best) pull the common code out of _M_mutate and
_M_clone and make them and reserve() all call it.

I'm not so much interested in saving bytes as in centralizing
complexity.  basic_string<> is tricky and will get more so
when it is made thread-safe.

Nathan Myers
ncm@cantrip.org

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]