[Bug libstdc++/29037] performance problem with std::string operator=(const std::string& str);
pcarlini at suse dot de
Tue Sep 12 20:18:00 GMT 2006
------- Comment #6 from pcarlini at suse dot de 2006-09-12 20:18 -------
(In reply to comment #5)
> Why would this be faster ?
> The resize() happend only once at the beginning, before the iteration starts.
> And even with the reserve(), the reserve() would happen everytime before the
> inner loop (which iterates over the vector), and then the memory allocations
> would happen ?
"problematic" are string assigns, not += and you are moving the reserve *after*
the assign. The reason of that is simply that string assigns try to exploit
reference counting to reduce the amount of deep copies. But, again, just try or
look at the sources. Trust me, being the maintainer of the string class, these
are basic things.
> What's the exact difference between reserve() and resize() ?
Likewise, just look at the sources (we are on free software projects, right? ;)
or study the standard or the manuals around. Resize to a bigger size basically
is the same as reserve + a fill of default-constructed chars on the tail. You
don't need the last part, right?
More information about the Gcc-bugs