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: "neundorf at kde dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Sep 2006 17:55:27 -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 #5 from neundorf at kde dot org 2006-09-12 17:55 -------
std::string cacheKey;
for (...several files...)
{
cacheKey=current.FileName;
cacheKey.reserve(4*1024);
for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
{
cacheKey+=*i;
}
... do something
}
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 ?
What's the exact difference between reserve() and resize() ?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29037