This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/29037] performance problem with std::string operator=(const std::string& str);
- From: "pcarlini at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Sep 2006 20:18:43 -0000
- Subject: [Bug libstdc++/29037] performance problem with std::string operator=(const std::string& str);
- References: <bug-29037-13236@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #6 from pcarlini at suse dot de 2006-09-12 20:18 -------
(In reply to comment #5)
> Why would this be faster ?
Just try...
> 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?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29037