Change representation of dynamic arrays?

Walter Bright newshound1 at digitalmars.com
Sat Oct 20 01:22:11 PDT 2007


Janice Caron wrote:
> On 10/20/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> 
>> 2) Doesn't break array.length as rvalue, as this is rewritten by the
>> compiler as (array.end - array.start).
> 
> That's pointer arithmetic, of course, so looked at in pure assembler
> terms, we're talking ((array.end - array.start) / element.sizeof)
> 
> Is there any performance cost to the divide, or is optimised to be a
> right shift (at least where it can be)?


Divides are expensive. It's mitigated by:
1) most of the time, it's 1
2) most of the rest of the time, it's a power of 2 and optimized to shift
3) some of the rest of the time, it can be skipped as it divides then 
multiples by the same amount.



More information about the Digitalmars-d mailing list