a text on optimizing C++

David Leimbach kde-optimize@mail.kde.org
Fri, 24 Jan 2003 07:27:58 -0600


On Friday 24 January 2003 07:24 am, David Faure wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Friday 24 January 2003 14:18, David Leimbach wrote:
> > >  It looks almost the same, but the latter may also sometimes produce
> > > shorter code. Upon entering the constructor body, all constructors of
> > > attributes have already been executed. So in this example, in the
> > > latter case attr2 is directly initialized using a copy constructor,
> > > while in the sooner case it's initialized using the default
> > > constructor, and then operator= is used.
> >
> > So your claim is that with the initializer list the following has a
> > shorter execution path?
> >
> > SomeClass obj = someOtherObj;
> >
> > I don't think operator = is involved at all in the above line of code
> > regardless of whether the constructor uses initializer lists or not.  The
> > above is *not* an assignment so why would it use the assignment operator?
> > The above is an initialization that just happens to use the '=' token.
>
> Yes it's an initialization. But the constructor has already initialized
> the member object. This isn't about SomeClass obj = ...
> but about
>   m_obj = ...
> vs
>  Class::Class() : m_obj( ... ) {}

Ah... Not enough coffee it seems!  I was looking at the end result of how the 
user would call a constructor using initializer lists vs a function body... 
not how the constructor itself behaves. 

/me slips back into the corner again :)

Dave