D 50% slower than C++. What I'm doing wrong?

Timon Gehr timon.gehr at gmx.ch
Sun Apr 15 14:51:32 PDT 2012


On 04/15/2012 02:23 PM, Kevin Cox wrote:
>
> On Apr 15, 2012 4:30 AM, "Joseph Rushton Wakeling"
> <joseph.wakeling at webdrake.net <mailto:joseph.wakeling at webdrake.net>> wrote:
>  > ... the compiler accepts it.  Whether that's because it's acceptably
> pure, or because the compiler just doesn't detect this case of impurity,
> is another matter.  The int k is certainly mutable from outside the
> scope of the function, so AFAICS it _should_ be disallowed.
>
> As far as I understand pure includes the "hidden this parameter"  so it
> is pure if when you call it on the same structure with the same
> arguments you always get the same results.  Although that seams pretty
> useless in the optimization standpoint

It is useful, because the guarantees it gives still are quite strong. 
Besides, mutation of the receiver object can be explicitly disabled by 
marking the method const or immutable; there is no reason why 'pure' 
should imply 'const'.

> because the function can modify
> it's own object between calls.
>

S foo(int a)pure{
     S x;
     x.foo(a);
     x.bar(a);
     return x;
}


More information about the Digitalmars-d-learn mailing list