This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug libstdc++/29037] performance problem with std::string operator=(const std::string& str);



------- 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


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