Why is this D code slower than C++?

Lionello Lunesu lio at lunesu.remove.com
Thu Jan 18 00:09:24 PST 2007


%u wrote:
> == Quote from Bill Baxter (dnewsgroup at billbaxter.com)'s article
>> I noticed that it doesn't work properly with -release add to the
>> compiler flags.
> That is because in testapp.d the call of RegisterClass is put into
> an assertion.
> 
> On my machine the -release flag brings another 25%.
> 
>> The inout on the Ray parameter and the other changes to this
>> function alone change my D runtime from 22 sec to 15 sec.
> 
> The compiler should be smart enough to detect, that the Ray
> parameter is not used as an lvalue and thus can be replaced by a
> reference.

No, it can't.. Passing a struct by ref will result in unexpected 
behavior if it changes in some other thread. As always, the default 
should be safe no matter what, and that means copying the struct's contents.

I guess a new modifier like "byref" is the only option..

L.


More information about the Digitalmars-d-learn mailing list