Passing array as const slows down code?

Steven Schveighoffer schveiguy at yahoo.com
Thu May 3 07:07:07 PDT 2012


On Wed, 02 May 2012 16:05:13 -0400, Joseph Rushton Wakeling  
<joseph.wakeling at webdrake.net> wrote:

> On 30/04/12 16:03, Steven Schveighoffer wrote:
>> Try removing the ref and see if it goes back. That usage of ref should  
>> not
>> affect anything (if anything it should be slower, since it's an extra  
>> level of
>> indirection).
>
> Removing the ref ups the time as described before, but only with GDC  
> (DMD the runtime is the same).  It's a real effect.

I'm not familiar with GDC, but as bearophile says, it sounds like a  
compiler bug.  Maybe GDC is making an optimization in one case and not in  
the other, but both should be equivalently able to get the optimization.

>
>> There is no implicit local copy for const. I have a suspicion that you  
>> changed
>> two things and forgot about one of them when running your tests.
>
> Really don't think so.  You can even check the version history of  
> changes if you like!

IIRC, your original post concerned not-checked in code.  Anyway, if you've  
re-run the tests, this is a confirmation.  I'd go ahead and file a bug  
against GDC.  Rest assured, const should not *slow down* anything.

-Steve


More information about the Digitalmars-d-learn mailing list