why $ is need to access array [negative index]?
mipri
mipri at minimaltype.com
Fri Sep 18 20:49:47 UTC 2020
On Friday, 18 September 2020 at 20:46:00 UTC, mw wrote:
> On Friday, 18 September 2020 at 20:06:01 UTC, Steven
> Schveighoffer wrote:
>>
>> I would say no. The indexing code lowers to a machine
>> instruction. Making it so a negative value means something
>> else means every single indexing operation is going to have to
>> check whether it's negative, and if so do something completely
>> different.
>
> Currently we have range check on every single indexing
> operation already; so the trade-off here is: adding one more
> check v.s. the convenience it buys.
Range checks that never fire because your code isn't buggy
are very friendly to the branch predictor. Negative-indexing
checks are not so friendly.
More information about the Digitalmars-d
mailing list