[cmake-developers] dependency scanning speed
Alexander Neundorf
neundorf at kde.org
Mon Sep 11 10:57:04 EDT 2006
On Monday 11 September 2006 15:02, Bill Hoffman wrote:
> At 05:46 PM 9/10/2006, Alexander Neundorf wrote:
> >3) it uses std::string::resize(4*1024) to preallocate space for the
> > strings, and then assigns always c_str() instead of the std::string
> > itself, since assigning the std::string apparently throws away the
> > preallocated memory so that the memory has to be allocated again if the
> > string grows (which it does often when creating the key for the header
> > location cache). This saves another 4 seconds.
>
> This one concerns me. Is this always legal to do?
Why shouldn't it ?
std::string s1;
s1.resize(1024);
std::string s2="abc";
s1=s2; // -> slow, throws away the allocated memory
s1=s2.c_str(); //faster, also a deep copy, but doesn't throw away the
preallocated memory
In the worst case it wouldn't be faster anymore.
Bye
Alex
--
Work: alexander.neundorf AT jenoptik.com - http://www.jenoptik-los.de
Home: neundorf AT kde.org - http://www.kde.org
alex AT neundorf.net - http://www.neundorf.net
More information about the cmake-developers
mailing list