pure functions/methods

bearophile bearophileHUGS at lycos.com
Fri Apr 20 04:13:25 PDT 2012


Namespace:

> So only GDC optimized "pure" functions at all?

I've seen DMD performs some optimizations with "strongly pure" 
functions that return integral values.

If you have code like:

int sqr(in int x) pure nothrow { return x * x; }

int y = ...
auto r = sqr(y) + sqr(y);

I think DMD replaces that with this, even when inlining is 
disabled:

int y = ...
auto r = sqr(y) * 2;

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list