[cmake-developers] dependency scanning speed

Tanner Lovelace clubjuggler at gmail.com
Mon Sep 11 12:05:03 EDT 2006


On 9/11/06, Alexander Neundorf <neundorf at kde.org> wrote:
> 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.

Ah.  I misunderstood.  For some reason I thought you
were using c_str() on the left hand side of the equals.
My bad.

Yes, assigning s1=s2.c_str() is definitely always legal since, iirc,
it will call the copy constructor that takes a c-string as input.

Cheers,
Tanner
-- 
Tanner Lovelace
clubjuggler at gmail dot com
http://wtl.wayfarer.org/
(fieldless) In fess two roundels in pale, a billet fesswise and an
increscent, all sable.


More information about the cmake-developers mailing list