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

Reply via email to