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]

basic_string<>::_M_mutate - patch


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

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