This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
basic_string<>::_M_mutate - patch
- To: libstdc++@sourceware.cygnus.com
- Subject: basic_string<>::_M_mutate - patch
- From: Nathan Myers <ncm@best.com>
- Date: Mon, 28 Jun 1999 19:41:58 -0700 (PDT)
- Reply-To: libstdc++@sourceware.cygnus.com
Ryszard wrote:
> All functions that modify the string (insert, append, assign, ...)
> call replace and replace calls _M_mutate.
>
> The current implementation of _M_mutate is a really inefficient solution.
> Every call of this function that grows the string leads to a reallocation!
> The storage between size() and capacity() is ignored!
I agree this is a bug. The first comparison should have been of
__nsize <= this->capacity(), not this->size(). I also agree that
the new interface is cleaner.
However, I would like to see the code cleaned up a bit. First, the
indentation is damaged, unless that's just an e-mail artifact. Second,
the special case of __len1 == __len2 is not worth the extra code; it
should be folded into the "must reallocate" case, which is essentially
a fancy clone().
Thank you, Ryszard, for catching this mistake.
Nathan Myers
ncm@cantrip.org