This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Optimal basic_string<>::append
- From: Ryszard Kabatek <Ryszard dot Kabatek at softax dot pl>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 18 Dec 2001 08:36:38 +0100
- Subject: Re: Optimal basic_string<>::append
- References: <3C1DE329.E94E70EE@softax.pl> <3C1E1FEE.63EB7F2D@unitus.it>
- Reply-to: Ryszard dot Kabatek at softax dot pl
Paolo Carlini wrote:
>
> Well, on third thought (hopefully the final one on my part :-) I believe
> that your approach, while safe, would not gain us much. That's why: the
> reserve call that you spare, either reallocates the string to the required
> capacity or not. In the second case it does'nt cost much. In the first
> case, the new reallocated string is un-shared and with the required
> capacity. As such, inside _M_mutate it is *not* reallocated (see the if at
> the beginning of _M_mutate). So...
Reserve allocates exact the required storage amount. Just try to append
1000000 one character strings to an empty string and you will see how
"good" is the current implementation. I sent a benchmark some months ago,
http://gcc.gnu.org/ml/libstdc++/2001-07/msg00030.html
and a patch
http://gcc.gnu.org/ml/libstdc++/2001-07/msg00170.html
In my opinion we need the call of reserve only for one purpose, to save
the iterators in the case s.append(s). I any other case it slows down any
aplication with many such calls (parser, ...).
I can prepare a patch for the current version this week.
--
Ryszard Kabatek