Optimize my code =)
John Colvin
john.loughran.colvin at gmail.com
Fri Feb 14 08:47:29 PST 2014
On Friday, 14 February 2014 at 16:40:31 UTC, Craig Dillabaugh
wrote:
> On Friday, 14 February 2014 at 16:00:09 UTC, Robin wrote:
>>
>> this(size_t rows, size_t cols) {
>> this.dim = Dimension(rows, cols);
>> this.data = new T[this.dim.size];
>> enum nil = to!T(0);
>> foreach(ref T element; this.data) element = nil;
>> }
>>
> I am no expert at optimizing D code, so this is a bit of a shot
> in the dark, but does your speed improve at all if you replace:
>
>> this.data = new T[this.dim.size];
>
> with:
>
> this.data.length = this.dim.size
Why would that make a difference here? They're (almost) identical
are they not? Certainly the body of the work, the allocation
itself, is the same.
More information about the Digitalmars-d-learn
mailing list