Code generation [was: suggestion: slight optimization for UT_String]


Subject: Code generation [was: suggestion: slight optimization for UT_String]
From: Mike Nordell (tamlin@algonet.se)
Date: Mon Mar 19 2001 - 13:00:40 CST


Randy Kramer wrote:
> rms@greymalkin.yi.org wrote:
> > Can we have a sort of middle point here?
> >
> > x = x * y should be replaced by x *= y
>
> (A newbie C/C++ question:)
>
> Just out of curiosity, is that just a "cosmetic" change, or does that
> actually change the machine code emitted by the compiler?

Both. It does affect semantics of the expression. For the expression
  x = x * y

the non-optimizing compiler generates something like
  tmp = x.operator*(y);
  x = tmp;

while
  x *= y
becomes
  x.operator*=(y);

For POD (Plain Old Data) types any reasonable optimizer generates the same
code, but for an unoptimized build or when using non-trivial objects it can
make quite a difference.

/Mike



This archive was generated by hypermail 2b25 : Mon Mar 19 2001 - 12:58:29 CST