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


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


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