Avoiding Range Checks in Slice Expressions
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 31 05:47:32 PDT 2014
On Sun, 30 Mar 2014 15:40:43 -0400, Nordlöw <per.nordlow at gmail.com> wrote:
> Does DMD currently avoid range checks in array slice expressions such as
>
> f(x[0..$/2])
> f(x[$/2..$])
>
> typically found in divide-and-conquer algorithms such as quicksort?
If they are range-checked, it would be a good addition to the optimizer to
remove them. My guess is that it is range-checked.
> If not, what would it require to implement it?
As a hack, you can use the pointer, which will not be range checked:
f(x.ptr[0..x.length/2]) // note you can't use $ because the pointer
doesn't have length
f(x.ptr[x.length/2..x.length])
-Steve
More information about the Digitalmars-d-learn
mailing list