This is the mail archive of the libstdc++@gcc.gnu.org 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]
Other format: [Raw text]

Re: Optimal basic_string<>::append


Nathan Myers wrote:

> On Mon, Dec 17, 2001 at 03:54:04PM +0100, Paolo Carlini wrote:
> > first blush, I think this is not ok. The reason is the following: if
> > _M_replace_safe, that is _M_mutate inside it, reallocates the string
> > (this happen when this != &str) and the string is not shared, the
> > iterators __k1 and __k2, pointing to the original memory area, becomes
> > invalid (when a string is reallocated because his capacity is exceeded
> > (vs because the _Rep becomes unshared) the original memory area is
> > freed!)
>
> Paolo, I think I agree with your third analysis.  In general, though,
> any operation that makes a string longer than existing capacity permits
> invalidates any iterators.  We should take advantate of every permitted
> opportunity to invalidate iterators because it allows us to share the
> representation on any subsequent copies.

Thanks for this suggestion.
Right now I'm hard at work on the insert members closely following the
approach we used for the assign(s).
I'm almost ready, 4 members over all are affected but only one does the real
work (the other three can be folded to it either trivially or by using the
same approach of the last assign clean up).

Cheers,
Paolo.



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