return

Jordi kde-optimize@mail.kde.org
Mon, 3 Feb 2003 13:12:29 +0100


El Lunes, 3 de Febrero de 2003 12:59, Jordi escribi=F3:
> There's a lot of methods, at least in my code that end ups returning true
> or false to tell if they were able to make a small operation in that cases
> what will be faster:
>
> A:
> bool advance()
> {
>   bool result=3Dtrue;
>   if (current_frame=3D=3D max_frame)
>     if (cyclic)
>       current_frame=3D0;
>     else
>       result=3Dfalse;
>   else
>     ++current_frame;
>   return result;
> }
>
> or
>
> B:
> bool advance()
> {
>   if (current_frame=3D=3D max_frame)
>     if (cyclic)
>       current_frame=3D0;
>     else
>       return false;
>   else
>     ++current_frame;
>   return result;
> }
>

s/result/true

> In case A a bool has to be allocated in that method but gcc is supposed to
> optimize that case.
> In case B the bool is get ridden and gcc is supposed to not be able to
> optimize that well....
>
> What's faster A or B?
>
> --
> Jordi
> http://development.bluesock.net
> _______________________________________________
> Kde-optimize mailing list
> Kde-optimize@mail.kde.org
> http://mail.kde.org/mailman/listinfo/kde-optimize