Re: const Rect&
Jack wrote:
For const Rect&, why wouldn't the author think that passing by value is
already efficient enough?
Did the author want to save this tiny bits of stack spaces?
Actually, caring too much about this would be a micro-optimisation and as
such shouldn't be performed at early stages of development. In that stage,
I would use a rule-of-thumb, and that says that any builtin type is passed
by value while aggregate types are passed by const reference.
Note that this doesn't mean this way is the most effective one. I have
optimised some code for a certain CPU where it performed marginally better
to pass a similarly sized structure by value. I guess that the reason it
might perform better is locality.
Example:
void function( XYZ const& x) {
if(x.flag)
do_this();
foo_bar();
if(x.flag)
do_that();
}
Without further knowledge of foo_bar(), the compiler must assume that the
call to it might have changed 'x' (as a side-effect), so it can't cache the
value of 'x.flag' in a register.
Anyway, if you are investing time on this, you are either in late stages of
development and squeezing out a few percent of performance or you are
wasting your time.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Michael W??hrmann, Amtsgericht Hamburg HR B62 932