<p>Am 10.11.2015 14:37 schrieb "Sven Barth" <<a href="mailto:pascaldragon@googlemail.com">pascaldragon@googlemail.com</a>>:<br>
><br>
> Am 10.11.2015 12:27 schrieb "Jürgen Hestermann" <<a href="mailto:juergen.hestermann@gmx.de">juergen.hestermann@gmx.de</a>>:<br>
> ><br>
> > Am 2015-11-10 um 11:32 schrieb Sven Barth:<br>
> >><br>
> >> The user doesn't need to know the detail that the value is kept in a temporary register, because that statement by itself is utterly useless for the user, as on load/store architectures like ARM you /always/ have values in registers if they are worked with and the compiler will happily spill around the contents if necessary.<br>
> ><br>
> ><br>
> > Does that mean, that local variables and with statements are treated completely identically?<br>
> > Are both held in registers with the same mechanism and will there never be an (speed) adavantage of one of them?<br>
> > If there is only the chance that it may speed up the code (even when only on certain platforms) then I would like to know it.<br>
><br>
> It always depends on the specific code (its complexity) and the specific compiler settings (optimizations) and maybe also the target architecture (because of register pressure and such). There is nothing general I can say /except/ that the with expression will be evaluated only once. Thus depending on the circumstances a local variable and the usage of with might behave the same. In simple cases the with /might/ be faster because it won't result in the expression result being stored on the stack, but that's by no means a given.</p>
<p>So... I quickly rechecked the code and can now make a more fundated statement. In case of a more complex expression (e.g. not a field that's a class or something like that) the expression will be stored in a temporary /variable/ not a register. Thus the generated code should be the same as for a local variable. For non complex expressions the value is used directly (e.g. as if the with didn't happen), though further optimizations (e.g. the regvars optimization) might improve that.</p>
<p>Regards,<br>
Sven</p>